PDA

View Full Version : Solved: Help with VBA and forms



cvernon
04-01-2009, 03:53 PM
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!

geekgirlau
04-01-2009, 05:09 PM
Can you post the code that you have so far?

cvernon
04-01-2009, 05:14 PM
Actually, I just got it working. My basic mistake was using ActiveDocument.Bookmarks instead of ActiveDocument.FormFields.

Thank you for responding though!

geekgirlau
04-01-2009, 06:02 PM
Would you like to post your code anyway? It may prove helpful to someone else in the future.

cvernon
04-01-2009, 06:08 PM
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. :banghead:

geekgirlau
04-01-2009, 06:16 PM
You could also try this:


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

cvernon
04-01-2009, 06:37 PM
Oh, that's much cleaner. Thanks!

fumei
04-02-2009, 10:06 AM
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).