Code:
'theDBguy's PDF Form Fields Demo
'accessmvp.com/thedbguy
'9/24/2017
'v1.0
'Demonstrates how to get a list of form field names from a fillable PDF form.
'-
'Copyright Notice
'This demo was originally created by theDBguy@gmail.com.
'You are free to use any code from this demo, provided you also include
'the following copyright notice wherever you use the code in your application.
'-
'Copyright Notice: The following code was originally written by theDBguy@gmail.com.
'You are free to use this code in your application, provided this copyright notice remains unchanged. All rights reserved."
Private Sub cmdDoSomething_Click()
On Error GoTo errHandler
Dim appAcro As Object
Dim docAcro As Object
Dim docPD As Object
Dim jso As Object
Dim fd As Object
Dim strFile As String
Dim lngCounter As Long
Set fd = Application.FileDialog(3) 'filepicker
'select PDF file
With fd
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "PDF Files", "*.pdf"
.Title = "Locate PDF file"
If .Show Then
strFile = .SelectedItems(1)
Me.lblFilePath.Caption = strFile
Set appAcro = CreateObject("Acroexch.AVDoc")
If appAcro.Open(strFile, "") Then
Set docPD = appAcro.getPDDoc()
Set jso = docPD.getJSObject
'clear previous field list
Me.txtFields = Null
If jso.numFields > 0 Then
For lngCounter = 0 To jso.numFields - 1
Me.txtFields = Me.txtFields & jso.getNthFieldName(lngCounter) & vbCrLf
Next
MsgBox "Done!", vbInformation, "Demo"
Else
MsgBox "No form fields found!", vbInformation, "No Fields"
End If
'Close the PDF; the True parameter prevents the Save As dialog from showing
appAcro.Close True
Else
'unexpected Acrobat error
MsgBox "There was a problem reading the PDF file.", vbInformation, "Error"
End If
End If
End With
errExit:
'cleanup
Set fd = Nothing
Set jso = Nothing
Set docPD = Nothing
Set docAcro = Nothing
Set appAcro = Nothing
Exit Sub
errHandler:
MsgBox Err.Number & ": " & Err.Description
Resume errExit
End Sub
Private Sub Form_Open(Cancel As Integer)
Me.lblTitle.Caption = cDemoTitle & vbCrLf & cDemoVersion
End Sub
Private Sub txtEmail_Click()
Me.cmdFocus.SetFocus
ShellEx "http://www.accessmvp.com/thedbguy"
End Sub