Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2005

Tip: Looking for answers? Try searching our database.

Getting a dropdown value from the fields collection

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jack - 13 Sep 2005 17:51 GMT
Hello,

I have an application that is looping through the fields collection of a
Word document and gathering the entered values and subsequently loading those
values into an Access database.

Although I can get the value of the dropdown box from the Result property
when accessing the object using the formfields collection, I cannot seem to
get the value using the fields collection. To prevent significant coding
changes to my routine, can anyone advise me on how to get the value selected
in a dropdown formfield from the fields collection?

Thanks in advance!
Jack
Jay Freedman - 14 Sep 2005 04:09 GMT
>Hello,
>
[quoted text clipped - 10 lines]
>Thanks in advance!
>Jack

Hi Jack,

As the saying goes, you ain't gonna believe this one! As you saw
already, the Fields collection and the FormFields collection aren't
connected (how stupid is that?). Here's what you have to do to get
from here to there:

Sub foo()
   Dim oFld As Field
   Dim oRg As Range
   Dim oFfld As FormField
   Dim numrslt As Long
   Dim rslt As String
   
   For Each oFld In ActiveDocument.Fields
       With oFld
           If .Type = wdFieldFormDropDown Then
               Set oRg = .Result ' range of interior of dropdown
               ' expand the range by 1 char left & right
               oRg.MoveStart unit:=wdCharacter, Count:=-1
               oRg.MoveEnd unit:=wdCharacter, Count:=1
               ' grab the FormField from the range
               Set oFfld = oRg.FormFields(1)
               ' get the index of the selected value
               numrslt = oFfld.DropDown.Value
               ' get the text of the selected value
               rslt = oFfld.DropDown.ListEntries(numrslt).Name
               
               ' do what you like with it
               MsgBox rslt
           End If
       End With
   Next oFld
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Jack - 14 Sep 2005 12:55 GMT
Works perfectly. Thanks so much!

> >Hello,
> >
[quoted text clipped - 50 lines]
> Jay Freedman
> Microsoft Word MVP        FAQ: http://word.mvps.org
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.