Solved

MS Access VBA to update Adobe form checkbox and radiobuttonlist

Posted on 2013-01-30
10
1,554 Views
Last Modified: 2014-01-22
Hope you can help. I am ok with updating text boxes on an Adobe form via VBA, but not the Radiobutton list. A code sample would be great.

Code segment (text field updates, the checkbox and readiobuttonlist fields do not)

   
    'Update Text Field
    Set field2 = jso.getField("form1[0].#subform[1].#field[16]")
    field2.Value = "Field_16"  ' assign the fields value
   
    'Update Checkbox field
    Set field2 = jso.getField("form1[0].#subform[1].CheckBox1[0]")
    field2.Value = 1  ' assign the fields value

    'Update Radiobuttonlist field
    Set field2 = jso.getField("form1[0].#subform[1].RadioButtonList1[2]")
    field2.Value = 22  ' assign the fields value
   
    'Save the changes to the form
    theForm.Save PDSaveIncremental, cPDF
0
Comment
Question by:Charly999
  • 6
  • 4
10 Comments
 
LVL 57
ID: 38841321
No takers yet?   Let me see if I can't figure it out....

Jim.
0
 
LVL 57
ID: 38841394
Basically the code is sound.  Try passing it as text:

   'Update Checkbox field
    Set field2 = jso.getField("form1[0].#subform[1].CheckBox1[0]")
    field2.Value = "1"  ' assign the fields value

    'Update Radiobuttonlist field
    Set field2 = jso.getField("form1[0].#subform[1].RadioButtonList1[2]")
    field2.Value = "22"  ' assign the fields value

Jim.
0
 

Author Comment

by:Charly999
ID: 38841600
Jim, appreciate the feed back. I have dug deeper, and have found several things:

 1) I can see the updates in the PDF form when I have it open and I'm running the VBA code from MS Access.

  2) Problem seems to be when saving the form, the checkboxes and readiobutton values roll back to the initial values, so the updated values are lost.

  3) Others sites suggest the problem is with the checkboxes and radiobuttons being on the Master page in the pdf document.and therefore can't be updated using the above coding. They suggest using javascript.

So, I have tried javascript and that doesn't seem to be working either. The pdf is created by another group via livecycle, and I can't edit it in to place the controls on a design page.

Any help would be greatly appreciated. If you know the syntax for using javascript to update a specific checkbox on a form, that wouid help.

Thanks

Charly
0
 
LVL 57
ID: 38843828
Your working in a area with PDF's that I've never dealt with, so I really don't have anything to offer.

I'd have to have the PDF your working with and the code and take a stab at it to get anywhere.

Jim.
0
 

Author Comment

by:Charly999
ID: 38852064
Jim, here is code from the net and attached form. Does not seem to want to work. Thanks.


Public Sub Test2FromNet()

Dim FV, fn, txt

Set WshShell = CreateObject("Wscript.Shell")
WshShell.Run "Acrobat.exe C:\Temp\TestFile.pdf"
 
  '// Set/Get Acrobat Objects
Set App = CreateObject("AcroExch.App")
Set AVDoc = App.GetActiveDoc
Set PDDoc = AVDoc.GetPDDoc
Set jso = PDDoc.GetJSObject

  '// search for fields and get Name+value
txt = ""
If jso.numFields Then
  For i = 0 To jso.numFields - 1
     txt = ""
     fn = jso.getNthFieldName(i)
     Set f = jso.getField(fn)
     FV = f.Value
     If f.Type = "checkbox" Then
        f.Value = 1
    End If
     txt = txt & fn & "=" & FV & ";"
     'MsgBox (txt)
  Next
Else
  MsgBox ("No fields found")
End If


PDDoc.Save PDSaveIncremental, "C:\Temp\TestFile.pdf"
 
Set AVDoc = Nothing
Set PDDoc = Nothing
Set jso = Nothing

End Sub
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 57
ID: 38852566
Don't see an attachment...

Jim.
0
 

Author Comment

by:Charly999
ID: 38856488
Trying again w attachement. Selecting file from the "Browse" button, Clicking "Attach", seeing the barber pole spin, watching the browser status bar run out. Looks to me like it worked, but maybe not. I'll try again.
0
 

Author Comment

by:Charly999
ID: 38856853
Ok, attached added.
TestFile.pdf
0
 
LVL 57

Assisted Solution

by:Jim Dettman (Microsoft MVP/ EE MVE)
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 38857101
Hum, not sure what to tell you.  Code below seemed to work fine here.  Unchecked all the check boxes, save, re-opened and verified saved as un-checked, then ran the code.  All the boxes from "Category(s) of info:" and below were checked.

Jim.

Public Sub Test2FromNet()

Dim wshshell As Object
Dim app As Object
Dim AVDoc As Object
Dim PDDoc As Object
Dim jso As Object
Dim i As Integer
Dim f As Object

Dim FV, fn, txt

Const PDSaveIncremental = 0
 
Const PDSaveFull = 1
Const PDSaveCopy = 2
Const PDSaveLinearized = 4
Const PDSaveWithPSHeader = 8
Const PDSaveBinaryOK = 16
Const PDSaveCollectGarbage = 32
Const PDSaveForceIncremental = 64
Const PDSaveKeepModDate = 128

Set wshshell = CreateObject("Wscript.Shell")
wshshell.Run "Acrobat.exe C:\Temp\TestFile.pdf"
 
'// Set/Get Acrobat Objects
Set app = CreateObject("AcroExch.App")
Set AVDoc = app.GetActiveDoc
Set PDDoc = AVDoc.GetPDDoc
Set jso = PDDoc.GetJSObject

'// search for fields and get Name+value
txt = ""
If jso.numFields Then
  For i = 0 To jso.numFields - 1
     txt = ""
     fn = jso.getNthFieldName(i)
     Set f = jso.getField(fn)
     FV = f.Value
     If f.Type = "checkbox" Then
        f.Value = 1
    End If
     txt = txt & fn & "=" & FV & ";"
     Debug.Print txt
  Next
Else
  MsgBox ("No fields found")
End If

PDDoc.Save PDSaveIncremental, "C:\Temp\TestFile.pdf"

PDDoc.Close
Set PDDoc = Nothing
Set jso = Nothing
Set AVDoc = Nothing
Set app = Nothing


End Sub
0
 
LVL 57

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 500 total points
ID: 38857107
I should note however that I have Acrobat Standard installed on the machine I tested this on.

Jim.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now