0

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.

Erik A
  • 31,639
  • 12
  • 42
  • 67
Thomas Mebane
  • 1
  • 1
  • 1
  • 2
  • You should (at least) post exact code you're using and error message you get. (note: it's right you shouldn't post in the other question, if you have any issue you have to post your own question, that one is closed and accepted, even if from same author). – Adriano Repetti Jul 26 '13 at 08:34
  • @Adriano I added the code to my question. – Thomas Mebane Jul 26 '13 at 09:24
  • 1) Object not found in which line? 2) Are you sure you have registered AcroEch.XYZ COM objects??? – Adriano Repetti Jul 26 '13 at 09:25
  • I removed Option Compare Database from the code now it opens the CX.pdf then pops up an error "Run-time error '424' Object required" I click Debug and it points me to the first "jso.getField" line – Thomas Mebane Jul 26 '13 at 09:35
  • @Adriano I'm pretty sure it's i have refistered AcroEch objects. I use a similar code in my Excel spreadsheet right now and it works just fine. – Thomas Mebane Jul 26 '13 at 09:44

1 Answers1

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.