Populate pdf fields using vba
I'm trying to fill in an existing PDF file fields using access VBA by the code below. "User Name:" is one field on my pdf. I'm trying to enter a value to this field. When I run this with an appropriate file path it gives me an error saying: Run-time error '424': Object required. The Adobe file version is Adobe Acrobat XI Pro.
Private Sub Adobefill_Click()
Dim FileNm, gApp, avDoc, pdDoc, jso
FileNm = "C:\projects\test\"
Set gApp = CreateObject("AcroExch.app")
Set avDoc = CreateObject("AcroExch.AVDoc")
If avDoc.Open(FileNm, "") Then
Set pdDoc = avDoc.GetPDDoc()
Set jso = pdDoc.GetJSObject
jso.getfield("User Name:").Value = "[user name redacted by moderator by request]" '<-------- I get an error here
pdDoc.Save PDSaveIncremental, FileNm 'Save changes to the PDF document
pdDoc.Close
End If
'Close the PDF; the True parameter prevents the Save As dialog from showing
- avDoc.Close (True)
'Some cleaning
Set gApp = Nothing
Set avDoc = Nothing
Set pdDoc = Nothing
Set jso = Nothing
End Sub
