This post relates to Excel, but the VBA would work in Access as well.
https://www.excelforum.com/excel-programming-vba-macros/1204659-writing-excel-data-into-pdf-form.html
It reads a pdf form to get all the field names and current values, and can also write to them as well.
I've adapted it to look loop through whatever fields it finds, rather than hard coding the field names.
Posting my slightly adjusted code below as well.
I am only beginning this journey of writing to a pdf...so can't offer much more help than this.
I'm about to explore what happens when I try to write to a field that doesn't exist.....
Good Luck,
Mal.
Sub ReadAdobeFields()
'Note: Remember to add your Adobe Acrobat Library in the VB Environment.
'Tools, References, Select the Adobe Acrobat Library.
row_number = 10 'Adjust for where to start on Sheet.
Dim AcrobatApplication As Acrobat.CAcroApp
Dim AcrobatDocument As Acrobat.CAcroAVDoc
Dim fcount As Long
Dim sWrkshtName As String
Dim sFileName As String
'On Error Resume Next
Set AcrobatApplication = CreateObject("AcroExch.App")
Set AcrobatDocument = CreateObject("AcroExch.AVDoc")
sFileName = Range("D5").Value
If AcrobatDocument.Open(sFileName, "") Then
AcrobatApplication.Show
Set AcroForm = CreateObject("AFormAut.App")
Set Fields = AcroForm.Fields
fcount = Fields.Count ' Number of Fields
For Each Field In Fields
ActiveSheet.Range("D" & row_number) = Field.Name
ActiveSheet.Range("E" & row_number) = Field.Value
row_number = row_number + 1
Next Field
Else
MsgBox "FAIL", vbOKOnly
End If
'Close template file & Acrobat.
AcrobatDocument.Close True
'AcrobatApplication.Exit
Set AcrobatApplication = Nothing
Set AcrobatDocument = Nothing
Set Field = Nothing
Set Fields = Nothing
Set ActoForm = Nothing
End Sub
Sub WriteAdobeFields()
'Note: Remember to add your Adobe Acrobat Library in the VB Environment.
'Tools, References, Select the Adobe Acrobat Library.
row_number = 10 'Adjust for where to start on Sheet.
Dim AcrobatApplication As Acrobat.CAcroApp
Dim AcrobatDocument As Acrobat.CAcroAVDoc
Dim fcount As Long
Dim sFieldName As String
Dim sFolderPath As String
Dim sFileName As String
Dim sWrkshtName As String
Dim sTemplateName As String
Dim sDATAtoWrite As String
Set AcrobatApplication = CreateObject("AcroExch.App")
Set AcrobatDocument = CreateObject("AcroExch.AVDoc")
sTemplateName = Range("D5").Value
sWrkshtName = ActiveSheet.Name
'ADJUST to pass name of Template from each Worksheet
If AcrobatDocument.Open(sTemplateName, "") Then
AcrobatApplication.Show
AcrobatApplication.Maximize 1
Set AcroForm = CreateObject("AFormAut.App")
Set Fields = AcroForm.Fields
fcount = Fields.Count ' Number of Fields
For Each Field In Fields
sFieldName = ActiveSheet.Range("D" & row_number).Value
sDATAtoWrite = ActiveSheet.Range("F" & row_number).Value
'check to see if this field is one to write, skip if not
If IsEmpty(ActiveSheet.Range("G" & row_number).Value) = False Then
Fields(sFieldName).Value = sDATAtoWrite
ActiveSheet.Range("h" & row_number).Value = "Done!"
Else
ActiveSheet.Range("h" & row_number).Value = "skipped"
End If
row_number = row_number + 1
Next Field
'ORIGINAL CODE COMMENTED OUT HERE
' Fields("Adults").Value = sWrkshtName.Range("C2").Value
' Fields("Students").Value = sWrkshtName.Range("C30").Value
' Fields("Group Name").Value = sWrkshtName.Range("C17").Value
' Fields("Campers NameRow1").Value = sWrkshtName.Range("C5").Value
' Fields("Campers NameRow2").Value = sWrkshtName.Range("C6").Value
' Fields("Campers NameRow3").Value = sWrkshtName.Range("C7").Value
' Fields("lunch").Value = sWrkshtName.Range("C51").Value
Else
MsgBox "failure"
End If
'Save PDF File
'Leave open for edit/printing
'? Close original template file
sFolderPath = "C:\Users\Administrator\Desktop\ExcelFilesForV360"
sFileName = sFolderPath & "\" & Fields("GroupName").Value & "-" & Format(Date, "dd-mm-yy") & ".pdf"
Set AcroApp = CreateObject("AcroExch.App")
Set avdoc = AcroApp.GetActiveDoc
If Not (avdoc Is Nothing) Then
Set PdDoc = avdoc.GetPDDoc
PdDoc.Save PDSaveFull, sFileName
End If
'Close template file here.
'AcrobatDocument.Close 1
'AcrobatApplication.Exit
Set AcrobatApplication = Nothing
Set AcrobatDocument = Nothing
Set Field = Nothing
Set Fields = Nothing
Set ActoForm = Nothing
End Sub