Accessing bookmarks in Word from Access

  • Thread starter Thread starter Rose B
  • Start date Start date
R

Rose B

I have developed some code in a 'test' database to open a Word document and
go through all of the bookmarks to extract data. In the 'test' database it
compiles and works fine, but when I have copied the code onto the application
where I want to incorporate it I get a compile error of Variable not Defined.
The error highlights "FormField" in the line of code below. I have checked
the References and everything is the same in both databases - anyone got any
ideas of why this would be happening?

For Each FormField In myWordDoc.Bookmarks
 
My guess is that you've told VBA to insist that all variables be defined in
one database and not in the other. (Look for "Option Explicit" at the top of
the module...)

You need to ensure that you've declared FormField as a variable:

Dim FormField As Word.Bookmark

or

Dim FormField As Object
 
Back
Top