0 Replies Latest reply on Jan 12, 2010 5:22 PM by christian_bahnsen

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

    christian_bahnsen Level 1

      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