Cannot submit programmatically to SQL server - InfoPath Dev
in

InfoPath Dev

Cannot submit programmatically to SQL server

Last post 11-01-2010 09:25 PM by josera. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 11-01-2010 09:25 PM

    • josera
    • Not Ranked
      Male
    • Joined on 07-27-2010
    • Sacheon (South Korea)
    • Posts 9

    Cannot submit programmatically to SQL server

    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:

    1. Open the second form
    2. Fill out the form
    3. 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:

    1. Open the second form
    2. Fill out the form
    3. Save the second form to a file
    4. Close the second form
    5. Change the contents of the file
    6. Rename the file
    7. Open the modified  and renamed file
    8. 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

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