-
Solved: Help with VBA and forms
The goal: I’m trying to automate Word so that when a particular choice is made on a form dropdown list it changes what the current choice is on a different dropdown list.
Example
List 1 (Bookmark name: Member) has the following choices
Bob
Chuck
Mark
List 2 (Bookmark name: Number)
1
2
3
So if I select Bob from List 1, List 2 automatically sets itself to 1. When trying to do this, I am getting an error that prohibits this because Word is in a protected state, but if I turn protection off the drop down lists don’t work anyway.
Thanks!
-
Can you post the code that you have so far?
-
Actually, I just got it working. My basic mistake was using ActiveDocument.Bookmarks instead of ActiveDocument.FormFields.
Thank you for responding though!
-
Would you like to post your code anyway? It may prove helpful to someone else in the future.
-
Sure!
Select Case ActiveDocument.FormFields("Member").Result
Case "Bob"
ActiveDocument.FormFields("Number").Result = "1"
Case "Chuck"
ActiveDocument.FormFields("Number").Result = "2"
Case "Mark"
ActiveDocument.FormFields("Number").Result = "3"
End Select
Simple as that...and it only took me hours to figure out.
-
You could also try this:
[vba]
With ActiveDocument.FormFields("Number")
Select Case ActiveDocument.FormFields("Member").Result
Case "Bob": .Result = "1"
Case "Chuck": .Result = "2"
Case "Mark": .Result = "3"
End Select
End With
[/vba]
-
Oh, that's much cleaner. Thanks!
-
Nice use of With statement geekgirlau.
cvernon: "My basic mistake was using ActiveDocument.Bookmarks instead of ActiveDocument.FormFields. "
Unfortunately - and I have no idea how this got going (although the Word MVP site has some responsibility I think) - this is very commonly used. Personally I think it is a bad idea to use one object (Bookmarks), when you actually mean another (Formfields).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules