Results 1 to 12 of 12
  1. #1
    bsc is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2011
    Posts
    28

    Question Retrieving a list of bookmarks in a Word Doc using Automation Server

    I have a table which maps a bookmark name to a tables field. The table values are then used to populate the word document using the word automation server. I'd like to present my users with a list of bookmarks, in a particular word document, in a combo box.



    My configuration table contains the 3 fields
    FilePath: Path to the word file containing the bookmarks.
    Bookmark: The bookmark name in the word document.
    Datafield: Field from which data will be pushed to the bookmark.

    My users will select the file path using a getfile dialog box. They will select the datafield using a dialog box listing field names available in the source table. I cant figure out how to give them a lookup box listing the bookamrks programed into the word doc listed in the FilePath field.

    Is this possible? Thanks for helping!
    -Bryan

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    This looks like what you want http://www.vbaexpress.com/kb/getarticle.php?kb_id=153

    I have never coded behind a Word document but I suppose that is where this could go. Instead of building the MsgBox string, add each bookmark to a combobox with AddItem method.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    bsc is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2011
    Posts
    28
    Ah… thank you. That is so simple. Now the Automation Server implementation is confusing me. I have this code which works the first time through. On the subsequent iterations I get an error on the "For" loop. The error is:
    Run-Time Error ‘462’: The remote server does not exist or is unavailable.

    My code looks like this.
    Public Sub GetBmks()
    Dim Reportpath As String
    Reportpath = "C:\Users\bcurl\Documents\Development\CoC Database\COCs\generic coc.docx"


    Dim bmk As Bookmark
    Dim msg As String
    Dim WordObj As Object

    On Error Resume Next
    Set WordObj = GetObject(, "Word.Application")

    If Err.Number = 429 Then
    ''Word is not running on this PC so start a new instance
    Set WordObj = CreateObject("Word.Application")
    End If

    On Error GoTo 0
    WordObj.Visible = True
    WordObj.Documents.Add Template:=Reportpath, NewTemplate:=False

    For Each bmk In ActiveDocument.Range.Bookmarks
    msg = msg & bmk.Name & vbCr
    'Forms![coc form registration].Combo13.AddItem Item:=bmk
    'Forms![coc form registration]![COCFormRegistrationSubform]!Form.BkMark.AddItem Item:=bmk
    Next bmk
    MsgBox msg
    WordObj.Quit
    Set WordObj = Nothing

    End Sub

  4. #4
    bsc is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2011
    Posts
    28
    Correction. The code above will run sucessfully 'every-other' iteration.

    -Even more confusing.
    Bryan

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I tested your code and it worked perfectly with both the message box and combobox.

    I did get that error when I misspelled form name and RowSourceType was set to Query. After corrections, all worked.
    I assume you have the combobox RowSourceType set to Value List?
    I used this syntax referring to form: Form_formname.Combo1
    I did not test with a subform.

    If you want to provide your files, will analyse.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    bsc is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2011
    Posts
    28
    I test this by running in the imediate window so the only other file needed would be the actual Doc file contaiing the bookmarks.

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I ran the code with the RunSub button on the VBA editor. Essentially same. Since I can't replicate the issue with my files, would have to analyze yours.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    bsc is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2011
    Posts
    28
    Let me package it up for you. How shall I deliver?

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Attach to post. Zip if too large. Attachment Manager is below the Advanced post editor.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    bsc is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2011
    Posts
    28
    First of all , thanks very much for helping me.
    The zip file is attached. It contains an ACCDB file with the module containing the code shown above, and a simple word document with bookmarks.
    Bryan

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I misunderstood meaning of 'every other iteration'. I thought you meant every other pass through the For Each loop. The issue is repeat run of the entire procedure. Kicks up Run-time error 462: The remote server machine does not exist or is unavailable. If I had done repeat runs of the code before I would not have asked you to post files.

    This offers solution http://support.microsoft.com/kb/189618

    Change code to:
    For Each bmk In WordObj.ActiveDocument.Range.Bookmarks
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    bsc is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2011
    Posts
    28

    Solved

    Sorry to have misled you there.

    Thank you so much. I am still trying to get the hang of the Automation Server and I have seen this solution before. Only reason it didn’t click is that the last time, the term "ActiveDocument.Range.Bookmarks" was preceded by a period like ".ActiveDocument.Range.Bookmarks" which gave me a clue that the term was abbreviated somehow.

    Again thanks….You have been invaluable to me. I appreciate this forum so very much.
    Bryan

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 03-18-2011, 03:22 PM
  2. Access Form to Word Bookmarks
    By markod in forum Forms
    Replies: 5
    Last Post: 12-27-2010, 05:18 PM
  3. Access and Word Automation
    By djreyrey in forum Forms
    Replies: 1
    Last Post: 01-08-2010, 02:33 PM
  4. font of word bookmarks
    By emilylu3 in forum Programming
    Replies: 1
    Last Post: 03-09-2006, 12:07 PM
  5. Replies: 1
    Last Post: 12-21-2005, 12:27 AM

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