Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    MatthewGrace is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    159

    Can VBA pull data from a PDF "Fill-in" Form?

    Adobe .PDF files often come with built-in text fields so your customers can interactively fill out any kind of form digitally and email to you. An example is pictured below, with the built-in text fields in bluish color.



    My question is, does anyone know if Access VBA can somehow retrieve the contents of these .PDF forms after a customer fills it out and sends it back to me? Ideally some kind of Object will allow me to manipulate pdf file contents, but I don't know where to begin...


    Click image for larger version. 

Name:	pdf Orderform.jpg 
Views:	64 
Size:	101.7 KB 
ID:	26926

  2. #2
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,789
    Looks like a daunting task to me. If you're generating the pdf form for a customer to fill out and return to you, it might be better to use some other tool that you can still send to the customer but integrate with Access, such as Word or Excel. At least a .doc or .xlsx can have protected fields/cells and function as a form quite easily, and is, AFAIK, much easier to integrate with Access. Adobe is, as you know, not native to MS Office, so I think that's a big hurdle. Here's something that might get you started on the path you've inquired about (note that this page references earlier articles that seem quite important to the task although I did not review them).
    http://khkonsulting.com/2010/09/read...elds-with-vba/
    Last edited by Micron; 01-04-2017 at 11:07 PM. Reason: grammar
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    MatthewGrace is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    159
    I just found this "Interapplication Communication Developer Guide" from Adobe. I'm not quite at the level enough to comprehend this but I'm close enough to force myself to experiment and probably get the hang of it. Unfortunately, as I have lamented before, there are not many clear cut tools for going from intermediate to advanced skill levels when learning VBA. Especially as it concerns using Objects, which is where it seems like the most power really is.

    http://www.adobe.com/content/dam/Ado...oper_guide.pdf

    Apparently, in the VBA editor you can go to Tools>>References, and checkmark the stuff with Acrobat in the name "Typekit something ..." and all of a sudden you can type stuff like "Dim someVariable As Acrobat.CAcroApp" and many other new classes. I have no idea how to work with those classes - other than to fudge with the advanced code written in the manual linked above. The documentation is nowhere near as thorough as MSDN.

    I will mark as solved in a couple days if nobody else chimes in. Thanks Mr. Micron.
    Edit: And I realize the information you linked also corroborates with the .pdf above. I believe it will improve the likelihood of me getting my desired outcome. Thank you again.

  4. #4
    MatthewGrace is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    159
    I can kiss you. Got it.

  5. #5
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,789
    Not sure my wife would approve...
    Sounds like you were successful. Could you elaborate on what 'got it' means? We all appreciate posted solutions. They help others who might have the same issue in the future.

  6. #6
    MatthewGrace is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    159
    Yes, you can use VBA to pull data from cells in a PDF file. There is no real additional explanation needed beyond the two links both of us shared. Yours was the most straight forward, and I will link the code again - which is rather self explanatory - just in case those links are broken in the future. Final thought: I want to repeat that the reason this was so tough for me is because there exists not enough clear documentation on how to manipulate Objects for us programmers stuck at an intermediate skill level. Which ones do I link in Tools>>References? Confused, I just checkmarked everything starting with "Acrobat". Which variable do I "Dim" as what and why? And which properties/methods do I invoke and why? Fortunately, your example showed me a code snippet and simply copy/pasting it was enough to get me up and running. The PDF I linked above from Adobe will help me advance my knowledge beyond even what my OP even requested:

    Code:
    Private Sub CommandButton1_Click()
        Dim AcroApp As Acrobat.CAcroApp
        Dim theForm As Acrobat.CAcroPDDoc
        Dim jso As Object
        Dim text1, text2 As String
    
        Set AcroApp = CreateObject("AcroExch.App")
        Set theForm = CreateObject("AcroExch.PDDoc")
        theForm.Open ("C:\temp\sampleForm.pdf")
        Set jso = theForm.GetJSObject
    
        ' get the information from the form fields Text1 and Text2
        text1 = jso.getField("Text1").Value
        text2 = jso.getField("Text2").Value
    
        MsgBox "Values read from PDF: " & text1 & " " & text2
    
        ' set a text field
        Dim field2 As Object
        Set field2 = jso.getField("Text2")
    
        field2.Value = 13   ' assign the number 13 to the fields value
    
        ' get the information from the form fields Text1 and Text2
        text1 = jso.getField("Text1").Value
        text2 = jso.getField("Text2").Value
    
        MsgBox "Values read from PDF: " & text1 & " " & text2
    
        theForm.Close
    
        AcroApp.Exit
        Set AcroApp = Nothing
        Set theForm = Nothing
    
        MsgBox "Done"
    End Sub

  7. #7
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,789
    Turned out to be easier than I thought. I have a recollection of seeing that Adobe document before when I was trying to figure out the Acrobat object model a few years ago. Problem is, I can't remember why I was looking into it (it was not for reading a pdf form) but I do recall giving up on the notion. That's why I anticipated it would be harder than it turned out to be.

    Regarding your comments on references, unless we know exactly which ones are required, it's a guessing game. But what you can do is either (or both) one at at time, remove the ones that appear to be not applicable to the task and test until it fails, or research the reference file name. We can't really expect one software company to fully support integration of their product with any or all of the others that might come into play, so I hear your lament, but I don't really expect things to be a whole lot different.

    Not sure if your code contains a cut and paste error, but I don't see the need for repeating the blocks pertaining to 'get the information from...
    Anyway, good luck with the rest of your project.

  8. #8
    JrMontgom is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Vero Beach, FL USA
    Posts
    124
    I think the user was using what I caall the "Pants and Suspenders" code to verify and show the rest of us both the setting and gettting data from a PDF field.

  9. #9
    AccessPower's Avatar
    AccessPower is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Oct 2016
    Posts
    165
    This is definitely possible. I've done it both ways, to and from a PDF. You just have to know the names of the fields within the pdf file for it to be possible.

  10. #10
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,789
    Quote Originally Posted by JrMontgom View Post
    I think the user was using what I caall the "Pants and Suspenders" code to verify and show the rest of us both the setting and gettting data from a PDF field.
    Never heard that phrase. Could you explain what you mean, 'cause I've scrutinized the code and don't see a difference. Then again, I've made that mistake before...
    Code:
      ' get the information from the form fields Text1 and Text2
        text1 = jso.getField("Text1").Value
        text2 = jso.getField("Text2").Value
    .....
        ' get the information from the form fields Text1 and Text2
        text1 = jso.getField("Text1").Value
        text2 = jso.getField("Text2").Value
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  11. #11
    MatthewGrace is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    159
    Hey Micron, I too thought it was weird on paper saying to myself ... "Why did he demo the same code twice?" When I ran the code it was made immediately clear:
    Step 1) Msgbox showing we can getfields with this syntax.
    Step 2) Demonstrate syntax to change a value.
    Step 3) The exact same code as step 1, only now the Msgbox will show your changed value from step 2... to prove step 2 really did something.
    That's it!

  12. #12
    DPoirier is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2018
    Posts
    2
    I've been able to use the Acrobat object in MS Access VBA to pull PDF form fields into a form. However, the users that will use the MS Access Application only have Adobe Reader. Therefore, they do not have access to the Acrobat object. Is there another method that does not require my users to have Adobe Pro?

  13. #13
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,411
    Not so far as I am aware, but take a look at this link which is about populating a pdf form from access. you might be able to modify the code to extract the data from a pdf

    http://www.accessmvp.com/thedbguy/de...llablepdf.html

    also take a look at this link

    https://stackoverflow.com/questions/...d-to-worksheet

  14. #14
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,789
    @DPoirier: Note that in the first link in the Additional Info section, it tells you where you can go to discover the pdf form field names if you don't know them. If you created the form (you don't say) then you ought to know them already. AFAIK, db users don't need Adobe; just Acrobat Reader so the db can open the pdf and either get data from, or populate data into, those form fields.

    I think the Acrobat object you're referring to is the one created in Access code? As long as you have the required dll reference, that shouldn't be a problem?
    Last edited by Micron; 08-30-2018 at 09:17 PM. Reason: added info

  15. #15
    DPoirier is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2018
    Posts
    2
    Thanks, Micron. I can pull the form fields and do know the names. I'm doing it on my own PC. However, the Acrobat dll comes only with Adobe Professional. This library cannot be used if you have Adobe Reader. Adobe documentation explains this as well. I would just hoping someone else had another solution.

    Thanks!

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 02-23-2016, 04:42 PM
  2. Replies: 1
    Last Post: 09-07-2015, 08:00 AM
  3. Fill in data into table upon "on click"
    By teekc in forum Forms
    Replies: 4
    Last Post: 04-01-2014, 08:27 PM
  4. Replies: 5
    Last Post: 02-05-2013, 10:57 PM
  5. Replies: 2
    Last Post: 09-29-2012, 11:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums