I've been able to successfully write a function using Visual Basic to pull text data from a MS Access database and write it to a LiveCycle form. The current problem is with Checkboxes. I'm able to set a 0 or 1 (checked or un-checked), but when the form is saved using the jso.SaveAs function, the new state of the checkboxes is not saved.
I searched the forums and found a similar question being asked, but it was nearly 10 years ago. I'm assuming Adobe would have fixed the API or provided examples on how to use it properly. Does anyone have any insight on how to change and save Checkboxes using VBA?
Below is my code:
Private Sub generatePDF()
Dim AcroApp As Acrobat.CAcroApp
Dim theForm As Acrobat.CAcroPDDoc
Dim jso As Object
Set AcroApp = CreateObject("AcroExch.App")
Set theForm = CreateObject("AcroExch.PDDoc")
theForm.Open ("C:\temp\Form.pdf")
Set jso = theForm.GetJSObject
'No problems setting the following text fields
jso.getField("form1[0].Page1[0].text19[0]").Value = "Text Value 1"
jso.getField("form1[0].Page1[0].text20[0]").Value = "Text Value 2"
jso.getField("form1[0].Page1[0].text21[0]").Value = "Text Value 3"
'Checkboxes are unchecked
msgbox ("Checkbox 2 is: " & jso.getField("form1[0].Page1[0].checkbox2[0]").Value)
msgbox ("Checkbox 8 is: " & jso.getField("form1[0].Page1[0].checkbox8[0]").Value)
'The checkboxs are checked
jso.getField("form1[0].Page1[0].checkbox2[0]").Value = 1
jso.getField("form1[0].Page1[0].checkbox8[0]").Value = 1
'Verify checkboxes are checked
msgbox ("Checkbox 2 is: " & jso.getField("form1[0].Page1[0].checkbox2[0]").Value)
msgbox ("Checkbox 8 is: " & jso.getField("form1[0].Page1[0].checkbox8[0]").Value)
'When saving the form, the checkboxes are returned to their default value of unchecked
jso.SaveAs "c:\temp\New-Form.pdf"
theForm.Close
AcroApp.Exit
Set AcroApp = Nothing
Set theForm = Nothing
End Sub