Pretty desperate here. Please help.
From a first form I open a second form programmatically. All operations on the second form are done programmatically. These operations are:
-
Open the second form
-
Fill out the form
-
Submit it to its "SQL server" DB
But I get this message: InfoPath cannot submit the form. The form does not contain any new data to submit to the data source.
The data is shown on the screen, so obviously is changed.
The first form submits if I do the same operations programmatically in it.
I have tried all the workarounds that I could think of but I always get the same error message. It only works if I manually change something.
This is the code that I use:
' Open the second form
dim objXDoc
set objXDoc = Application.XDocuments.NewFromSolution("\\Ssa\processes\InfopathTemplates\CronoNumber.xsn")
' Fill out the second form
dim f
set f = objXDoc.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:CronoNumbers/@DocumentType")
f.text = "Purchase Order"
' Submit the second form
objXDoc.Submit
The second form works perfectly when used manually.
One of the workarounds I have tried, also programmatically, is this:
-
Open the second form
-
Fill out the form
-
Save the second form to a file
-
Close the second form
-
Change the contents of the file
-
Rename the file
-
Open the modified and renamed file
-
Submit it to its "SQL server" DB
and still get the same error message. This is the code:
' Open the second form
dim objXDoc
set objXDoc = Application.XDocuments.NewFromSolution("\\Ssa\processes\InfopathTemplates\CronoNumber.xsn")
' Fill out the second form
dim f
set f = objXDoc.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:CronoNumbers/@DocumentType")
f.text = "Purchase Order"
' Save the form in a temporary file
objXDoc.SaveAs("C:\\MyForm.xml")
' Close the form
objXDoc.CloseDocument
' Open the file
const ForReading = 1, ForWriting = 2
dim objFSO
dim strFile
dim tf
Set objFSO=CreateObject("Scripting.FileSystemObject")
set tf = objFSO.OpenTextFile("C:\\MyForm.xml", ForReading)
strFile = tf.ReadAll
tf.Close
' Modification of the file
dim re, s
set re = new RegExp
re.Pattern = "DocumentType=""Purchase Order"""
s = re.Replace(strFile, "DocumentType=""New content""")
Set re = Nothing
' Write the modified file with different filename
set tf = objFSO.OpenTextFile("C:\\MyForm1.xml", ForWriting, true)
tf.Write(s)
tf.Close
set tf = nothing
' Open the modified file
dim objXDoc1
set objXDoc1 = Application.XDocuments.Open("C:\MyForm1.xml")
' Submit the second form
objXDoc1.Submit
I have tried to get it to work for several days, I have googled for it and I have not found any explanation or workaround.
I ran out of ideas to try. Please help.
Josera