PDA

View Full Version : Code with Drop Down form



philipad
11-07-2008, 04:06 AM
hi all,

I would like to write a code and use as input for the decision what the user will select from a Drop Down form

For example a drop down form has 2 choices, "2x2" and "3x3" i what the command that will tell if the result is 4 or 9

Thanks

OTWarrior
11-07-2008, 04:21 AM
I don't follow what exactly you are after, but If I understand correctly you could do a simple text case statement.

eg:


select case activedocument.formfields("DropDown1").result
case "2x2"
ddresult = 4
case "3x3"
ddresult = 9
end select

msgbox ddresult

fumei
11-07-2008, 10:15 AM
Assuming it is a formfield in the document.

philipad, can you give us more detail? Is this a formfield? Is this a combobox (a "dropdown") on a userform? Is this an ActiveX control in the document?

However, essentially, OT has given the answer. You test the value of the dropdown, and return the answer.

philipad
11-10-2008, 12:42 AM
I don't follow what exactly you are after, but If I understand correctly you could do a simple text case statement.

eg:


select case activedocument.formfields("DropDown1").result
case "2x2"
ddresult = 4
case "3x3"
ddresult = 9
end select

msgbox ddresult

Yeah that's what i meant!
Thanks a Lot OTWarrior
But still I have a problem...I am using Office 2003. TO use Forms I have to protect the document. The problem is that VBA cannot make changes to the text according to the code because the document is protected. Is there a way to bypass this protection?

OTWarrior
11-10-2008, 02:11 AM
Call this sub at the start and end of your code, and it will unprotect your document and protect it again.

Sub MegaUnprotect()
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:="Password"
Else
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="Password"
End If
End Sub