Creating a new record from an existing record - InfoPath Dev
in

InfoPath Dev

Creating a new record from an existing record

Last post 06-10-2010 01:06 PM by Joemanc. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 05-28-2010 10:27 AM

    Creating a new record from an existing record

    In Infopath, I'm trying to create a copy, or duplicate, of a record on one of my Infopath form's, so that when the user makes changes to the data shown on the form and then goes to save, a new record is added to the database.

    I tried to query using an ADODataConnection, and then in code setting the Primary Key ID to 0, and then using a me.submit command to see if that would try to save the record and re-issue the next unique Primary Key, but I got an error message.

    I don't see any other options off of the me.submit command. I'm not sure where to look or to start for that matter.

    Anyone have any ideas? Thanks.

  • 05-28-2010 12:28 PM In reply to

    Re: Creating a new record from an existing record

    Hi Joemanc,

     I am not sure if you have used DBXL before, if yes, there is a Side-by-side XTP that you can use for your existing Save or Submit button. You just need to clear the Key fields so that when you click the Save or Submit button, the information will be treated as a new form.

    Hope the above helps.

    Jose Cruz
    Software Test and Support Engineer
  • 06-10-2010 01:06 PM In reply to

    Re: Creating a new record from an existing record

    My solution may not work for everyone, and it may not be the most elegant, but it works. Here goes...

    Under a Duplicate button, I used SQL insert statements to copy each record I wanted to duplicate as a new one within code(see code below). Since I have multiple tables, I had to use an insert statement for each table. You'll also need to be aware of your primary keys when copying record(s) for each table. After I did the 1st insert, I did a query and retrieved the highest ID in that 1st table and stored this in a variable(see code). Once the records are copied for each table, I cleared out all the fields(see code below). Then, using the max ID in the stored variable, I queried using my Main Data Connection and used the stored ID in the variable.

    'sql statement

    strsql = "insert into assig(sysid, dmod, modby, spltamt) select " & lastsysid & ", '" & Now & "', modby, spltamt from assign where sysid = " & SysIDNumber.ToString

     'retrieve max ID

    strsql = "select max(sysid) as sysid from clntmtr"

    'clear out all fields 

    MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields", NamespaceManager).ReplaceSelf(initialData)

Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.