?
Solved

MS Access VBA to update Adobe form checkbox and radiobuttonlist

Posted on 2013-01-30
10
Medium Priority
?
1,727 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 58
ID: 38841321
No takers yet?   Let me see if I can't figure it out....

Jim.
0
 
LVL 58
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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 58
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
 
LVL 58
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 58

Assisted Solution

by:Jim Dettman (Microsoft MVP/ EE MVE)
Jim Dettman (Microsoft MVP/ EE MVE) earned 1500 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 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 1500 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

752 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