Skip to main content
Participating Frequently
January 13, 2010
Question

Opening and populating a PDF form with VBA code in Access 2007

  • January 13, 2010
  • 1 reply
  • 46040 views

I had posted this in Acrobat Windows.  It was suggested this (and the SDK forum) may be a better forum ...

I'm trying to load and then populate a PDF form programmatically using Access/VBA.  I'm patterning this after code that worked fine in Acrobat 5.0 but is throwing errors in Acrobat 9.  We're using Access 2007 on Windows XP and Vista computers.

The Access project has a reference to Adobe Acrobat 9.0 Type Library.  Attached is a jpg showing all the references in the Access project.

The error "Object variable not set (Error 91)" is happening with this statement:
Set PDDoc = AVDoc.GetPDDoc


Here is the code I'm trying to use.  I've always been a little fuzzy exactly which objects need to be created and the sequence they need to be created in.  Once I got it working in Acrobat 5 I left it alone.

    Dim WshShell As Object
    Dim myApp As Acrobat.AcroApp
    Dim AVDoc As Acrobat.AcroAVDoc
    Dim PDDoc As Acrobat.AcroPDDoc
    Dim PauseTime, Start

    Set WshShell = CreateObject("Wscript.Shell")
    ' run the Acrobat application within that shell and pass it a document name
    WshShell.Run "Acrobat.exe C:\Users\Christian\Documents\data\dist5\dist05_face_only_nh.pdf"
   
   
    '// Set/Get Acrobat Objects
    ' create an automation object that references the active copy of Acrobat
    Set myApp = CreateObject("AcroExch.App")
    ' reference the acrobat document we loaded above
    'Set AVDoc = CreateObject("AcroExch.AVDoc")
    Set AVDoc = myApp.GetActiveDoc()
   
    ' this apparently runs some method available to AVDOC
    Set PDDoc = AVDoc.GetPDDoc      '<------------------ THIS IS THE LINE THROWING THE ERROR
    ' this is how you reference the JSObject
    Set jso = PDDoc.GetJSObject
   
    ' let's clear the form
    temp = jso.resetForm()

   
    Set x = jso.getField("txt1_name")
    x.Value = "Bing Crosby"
   
    Set x = jso.getField("txt2_sex")
    x.Value = "Male"
   
    Set WshShell = Nothing
    Set myApp = Nothing
    Set AVDoc = Nothing
    Set PDDoc = Nothing

Thanks in advance for any help.

Christian Bahnsen

This topic has been closed for replies.

1 reply

lrosenth
Adobe Employee
Adobe Employee
January 13, 2010

How about downloading the Acrobat SDK and reading the documentation to understand what you've written?!?!

Participating Frequently
January 13, 2010

I'll give that another shot.  Hopefully the SDK has matured since last I perused it (back in version 5).  It was pretty sketchy then.  I recently got Acrobat 9 (mainly because I bought a laptop running Vista and my venerable version 5 wouldn't load thereon).  Does Adobe have the equivalent of MSDN?  I recall being very frustrated at the time I built the first application using the code above because I couldn't find code samples to test.

Thanks for your reply.

Participating Frequently
January 13, 2010

OK, downloaded the SDK, extracted from the zip, and poked around.  I wouldn't spurn any suggestions/assistance zeroing in on the content germane to my post. 

Thanks.