• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 823
  • Last Modified:

Need example of VBA code that will take data from stored procedure fields and place it in PDF fields.

Need an example of VBA code that will take data from stored procedure fields and place it in PDF fields.
  • 4
  • 2
1 Solution
Hi There,

My colleague had created an export feature from an Access database which exports data into xml format then using the Form->Import function on the PDF to import. This I assume is easier than using VBA coding perhaps?
Search for 'import data into PDF form' on the interwebs and you'll find something which will guide you.
Apologies, not a solution as such but as you have not given any examples etc, it's quite difficult to know of context and therefore exact solution.

answertimeAuthor Commented:
Thank you for your response Tony.  I am sure your XML solution is more elegant than VBA. Unfortunately for the app I am using I have to use VBA to take data from a stored procedure and insert it into fields in a pdf form.  I just need the basic VBA code for doing this sort of thing and then I can take it from there and award the points. Hypothetically let's say my stored procedure returns peoples first names, how do I get the name into the adobe field. The adobe fields is f1_01(0) and the stored procedure field is called name. Is it something like this?:
jso.getField(f1_01(0)).Value = name

answertimeAuthor Commented:
Thanks zorvek. I wasn't sure how to add zones.  Waiting patiently.
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

answertimeAuthor Commented:
I do know how to read data from a stored procedure into Excel.  The link you sent may do the other part of it.
I will let you know tomorrow and award points.
Signing off for the night.
Simon BallCommented:
here's what i found in my search...

you need adobe acrobat V7 plus ( the writer not the reader)..

then in vb6/vba you can call an adobe acrobat object and use some JSON to write data from office into an adobe pdf form.

there seems to be distiller and writer, 2 different systems from adobe for making forms...not sure if that has an effect.

here's the urls my research turned up, hope this helps:




In order to achieve this we have to make a reference in the excel program to the Adobe Acrobat 6.0 Type Library ( acrobat tlb). 

 the Excel Macro code example ( in which a field, named P1.REP in the PDF document will be set to the value "test test test" ) ( this macro is triggered in the Excel tax calculation program ) 

 Private Sub UpdatePDF()

 Dim gApp As Acrobat.CAcroApp
 Dim pdDoc As Acrobat.CAcroPDDoc
 Dim jso As Object

 Set gApp = CreateObject("AcroExch.App") ' make acrobat session
 Set pdDoc = CreateObject("AcroExch.PDDoc")

 If pdDoc.Open("C:\2762deel1-aang-N.c.pdf") Then ' the PDF document we want to fill in open it

 Set jso = pdDoc.GetJSObject ' set the Javascript object via this way we can fill in the PDF document fields

 If Not jso Is Nothing Then

 jso.getField("P1.REP").Value = "test test test " ' ' jso can be interpreted as" this" in javascript thus being a doc. The same javascript functions can be used in here.

 End If

 pdDoc.Save PDSaveIncremental, path ' save changes to the PDF document
 pdDoc.Close ' close the PDF document


 MsgBox ("Failed could not open PDF ")

 End If

 Set pdDoc = Nothing ' clear

 End Sub


 The "problem" is that this macro will only run on a machine where Acrobat is installed ( Reader or D istiller is not enough )

Open in new window

Simon BallCommented:
http://forums.adobe.com/thread/573895?tstart=-2... acrobat software required.
answertimeAuthor Commented:
Thank you!

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now