[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

VBA ForNext Loop to cycle through collection of Word Fields

Posted on 2004-03-30
3
Medium Priority
?
3,372 Views
Last Modified: 2008-03-06
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)
     ActiveDocument.Fields.Next
Next

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.

Thanks!
0
Comment
Question by:vivekpara
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
Tommy Kinard earned 2000 total points
ID: 10718534
Hi vivekpara,

The below sub will give you the name of each bookmark.

Sub UpdateDBWrdFields()
    Dim A As Word.Field
    Dim FldUpd As String
    For Each A In ActiveDocument.Fields
        If A.Result.Bookmarks.Count > 0 Then
            FldUpd = A.Result.Bookmarks(1).Name
        End If
    Next
End Sub

HTH
dragontooth

0
 
LVL 2

Author Comment

by:vivekpara
ID: 10727546
Great solution...worked like a charm.
0
 
LVL 14

Expert Comment

by:Tommy Kinard
ID: 10727589
Glad I could help!

dragontooth

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question