Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    stanito is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2022
    Location
    Seattle
    Posts
    6

    Question "Element not found" on iterating over an AFORMAUTLib.Fields object

    I don't normally do much with VBA or Access in general but I have a specific task to generate PDF forms given some data in an Access db.
    While learning the API, I'm trying to enumerate a form's fields by simply printing their names and types.

    Code:
        Dim file_path
        Dim avdoc As Acrobat.AcroAVDoc
        Dim acroapp As Acrobat.acroapp
        Dim form As AFORMAUTLib.AFormApp
        Dim fields As AFORMAUTLib.fields
        Dim field As AFORMAUTLib.field
       
        file_path = CurDir() & "\OoPdfFormExample.pdf"
        
        Set acroapp = CreateObject("AcroExch.App")
        Set avdoc = CreateObject("AcroExch.AVDoc")
        
        If Not avdoc.Open(file_path, "") Then
            
            Debug.Print "Can't open PDF"
            Exit Sub
            
        End If
       
        acroapp.Hide
        
        Set form = CreateObject("AFormAut.App")
        Set fields = form.fields
        Debug.Print "Count " & fields.Count
        
        For Each field In fields                                  ' <--- The error is thrown on this line
            Debug.Print field.Name & " of type " & field.Type
        Next field
    The above results in "Automation error Element not found."
    I have both Adobe Acrobat 10.0 Type Library and AFormAut 1.0 Type Library references checked.
    Attached is some random file I'm using for testing though I've tried other PDFs with forms as well.


    OoPdfFormExample.pdf
    I'm using Access 2019 (Version 2204 Build 16.0.15128.20128) and Adobe Acrobat Pro (2022.001.20117).

    Any help is much appreciated.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    stanito is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2022
    Location
    Seattle
    Posts
    6
    Perhaps I wasn't very clear in my original post..
    I'm attempting to enumerate PDF form fields following an example in Acrobat SDK docs.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Post 3 was moderated, I'm posting to trigger email notifications.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    why not use the doCmd.OutPutTo method?
    https://docs.microsoft.com/en-us/off...DoCmd.OutputTo

    I'm trying to enumerate a form's fields by simply printing their names and types.
    The forms or the pdfs?

    edit:Oops. someone came into my office while typing. I see my question was answered.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  6. #6
    stanito is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2022
    Location
    Seattle
    Posts
    6
    Quote Originally Posted by moke123 View Post
    why not use the doCmd.OutPutTo method?
    Thanks moke123. That might work but I'd have to recreate an existing fairly intricate PDF form in Access which contains signature blocks. I may be wrong but I assume placing those blocks would require the Acrobat API anyway.

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    Sorry, way off the mark then.

    I've not used the SDK or pretty much any SDK.
    Look at the Locals window to see what is created.?

    Try For each Field in form.Fields ?

    That link conveniently has the Field definition, but not Fields?

    Also wouldn't it be avdoc.fields?

    Quote Originally Posted by Welshgasman View Post
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    stanito is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2022
    Location
    Seattle
    Posts
    6
    Quote Originally Posted by Welshgasman View Post
    Sorry, way off the mark then.
    No worries, Welshgasman. I could do a better job at explaining the full situation.
    I followed this example and some others I found elsewhere that basically do the same thing. At first, it too struck me as odd that there's no apparent connection between fields and the form object; however, the SDK docs shed some light on why this is.
    EDIT: The Locals window shows fields as an array (or collection, I'm not sure of the correct term) but expanding it says "No variables." Interestingly, fields.Count does report a correct number of fields in the form, right above the line that croaks.

    As an alternative, I'll explore AcroPDDoc.GetJSObject and see if I have better luck with that.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Post 8 was moderated, I'm posting to trigger email notifications.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    See if the free tool mentioned here helps.
    https://community.adobe.com/t5/acrob.../td-p/10858906
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  11. #11
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    my guess is you dont have the correct references checked

    I checked all that I could see that where acrobat related and get this result running your code.

    Code:
    Count 17
    Address 1 Text Box of type text
    Address 2 Text Box of type text
    City Text Box of type text
    Country Combo Box of type combobox
    Driving License Check Box of type checkbox
    Family Name Text Box of type text
    Favourite Colour List Box of type combobox
    Gender List Box of type combobox
    Given Name Text Box of type text
    Height Formatted Field of type text
    House nr Text Box of type text
    Language 1 Check Box of type checkbox
    Language 2 Check Box of type checkbox
    Language 3 Check Box of type checkbox
    Language 4 Check Box of type checkbox
    Language 5 Check Box of type checkbox
    Postcode Text Box of type text
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  12. #12
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    I removed references 1 by 1 and here's whats left which works
    Click image for larger version. 

Name:	Screenshot 2022-04-29 143945.png 
Views:	15 
Size:	8.7 KB 
ID:	47719
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  13. #13
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    left out one important change I made

    I changed
    Code:
    file_path = CurDir() & "\OoPdfFormExample.pdf"
    to
    Code:
    file_path = CurrentProject.Path & "\OoPdfFormExample.pdf"
    assuming your storing the pdf in the app folder.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  14. #14
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    Nice one Moke
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  15. #15
    stanito is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2022
    Location
    Seattle
    Posts
    6
    Quote Originally Posted by Welshgasman View Post
    See if the free tool mentioned here helps.
    https://community.adobe.com/t5/acrob.../td-p/10858906
    Thanks, I'll check it out.

    Quote Originally Posted by moke123 View Post
    I removed references 1 by 1 and here's whats left which works
    Yep, had those checked from the start. Also changed the file_path.
    Perhaps there's a bug in the current release of the SDK or something else related to my setup.
    I'll try on a different machine later on.

    Click image for larger version. 

Name:	131.png 
Views:	9 
Size:	6.3 KB 
ID:	47720

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

Similar Threads

  1. Replies: 4
    Last Post: 08-09-2019, 06:38 PM
  2. Replies: 13
    Last Post: 12-12-2016, 12:26 AM
  3. Replies: 3
    Last Post: 02-06-2015, 03:22 PM
  4. Replies: 6
    Last Post: 10-04-2012, 01:43 PM
  5. Replies: 0
    Last Post: 01-11-2012, 12:34 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