Fill a PDF Form from MS Access

2019-09-04 12:03发布

问题:

I found a post on here on how to fill a fillable PDF from from MS Access.

It is a Visual Basic code for filling out a fillable PDF. I have been using Excel to perform this function and would like to migrate my database to Access and still keep the same functionality. I have figured out how to add my VB code to the button but when I click it gives me and error. Any help that can be giving would be greatly appreciated.

I have Adobe Acrobat X Pro and MS Access 2010. My PDF files was created in word and then converted to a PDF file, I know all my field names because I created them. The PDF document is saved as c:\CX.pdf, it has 9 pages, some examples of field names on the document are: “Plant Name”, “Station Location”, “Installer or Owner”. My MS Access Data Base Fields are named the same.

Option Compare Database

Private Sub Command105_Click()

Dim FileNm, gApp, avDoc, pdDoc, jso

FileNm = "c:\CX.pdf" 'File location
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("CX[0].Page1[0].Plant_Name[0]").Value = "Plant_Name"
    jso.getField("CX[0].Page1[0].Station_Location[0]").Value = "Station_Location"
    jso.getField("CX[0].Page1[0].Installer_or_Owner[0]").Value = "Installer_or_Owner"
    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

It was giving me the error "Object not found", now it's not giving me error but it's still not writing to the PDF.

回答1:

This is a bit old but it helped me in the long run. I did figure out what was wrong. "Object not found" means that the code cannot find the PDF field and therefore you can not assign anything to the object that "getFeild()" returns. The most likely culprit is that the "path" to the Field is incorrect. Try just putting the field name and you may need to export the data to a FTF file and read the file in notepad to find the field name.

the field names will look like

T/(FeildName)v/(FeildValue)

Once the object is actually being returned you'll be able to assign it a value.



标签: access-vba