VBA ForNext Loop to cycle through collection of Word Fields
Posted on 2004-03-30
I am trying to cycle through the list of word fields I have in my document. I have bookmarked the fields with the equivalent fieldname in my active database. What I want to do is to go through all fields on the document using a fornext loop to pull out the name of the field to use in my update routine. I want it to do something like this
For i = 1 to ActiveDocument.Fields.Count
fldupd = ActiveDocument.Fields.i.fieldname
--Line of code to update database -- (ActiveDocument.Field.i.fieldname, ActiveDocument.Bookmarks("fieldname").Range.Text)
I could also use a DoWhile command. I just want to be able to have it parse the fields and update the database in whatever order they appear in the collection. At the moment, I can't think of a way to do it. If you've got an answer, I'd love to hear it.
The reason I want to do it this way is so a Jr. Programmer can just add a field with the correct name to the form as necessay and update the database.