We have an Infopath 2007 form using managed code and that is hooked up to a SQL 2005 database. The database consists of 1 main table(unique ID field, identity), and 5 sub-tables linked to the main table on the same unique ID contained in the main table. We have a Main Menu view, with multiple views underneath.
Let's say the user enters their data in to the form, and submits via managed code. All data is submitted correctly and can be retrieved correctly.
Now, let's say an hour later, the user needs to enter in a new record. The user never closed the instance of Infopath, they just simply returned to the Main Menu view and then to the view that allows data entry. When they go to submit this time, a new record is properly created in the main table and the 5 sub-tables, BUT, the previous record they submitted an hour earlier in the main table is deleted, leaving orphans in the 5 sub-tables.
I tried to use the code found at this link to clear or reset fields, and while it seems to clear data in the form, the record is still deleted in the main table.
http://www.bizsupportonline.net/blog/2009/08/clear-reset-fields-infopath-3-lines-code/
Is there some code setting that we are missing to indicate to Infopath that we are trying to enter a new record? Or is there a way to reset the form or restore the InfoPath form to its original state as when it was opened for the first time?
For a quick work around we ended up setting a rule on a button to [close the form] and then [Open a new form to fill out]. This gives us what we want, but it's not a clean way to do it. Thanks!