PDA

View Full Version : DropDown Action



philipad
11-10-2008, 05:36 AM
Hi all,

I wrote a code to be used with a drop down form, which works fine if I press the "play" button in VBE. What i want is the action specified from code to be taken when I change a value from the dropdown form while I am in the word document. Can anyone help?

Thanks

lucas
11-10-2008, 09:54 AM
Post your example or at least the code. We have no way to know what you are looking at.

fumei
11-10-2008, 12:13 PM
Use an OnExit macro...if your dropdown is a formfield dropdown. If it is not a formfield dropdown, then you have to do something else.

Demo attached. One dropdown formfield. Make a choice, and press TAB to move out of the formfield. The OnExit macro fires, in this case simply displaying a messagebox indicating which choice was made. This could just as easily be executing a specific procedure for the given choice.

fumei
11-10-2008, 12:16 PM
Ummm, you have another thread on exactly the same question really. In it, OTWarrior gave you the precise answer already.

philipad
11-10-2008, 10:49 PM
Thanks fumei for your reply but this is not what I was asking. Maybe my post wasnt clear. I modified the document you attached to show you what I mean.
When I choose "two" from the dropdown form I want "2" to appear in another bookmark.
This can be done only If i unprotect the document and press "play" in the VBE. I want the change of the second vlue to occur automatically bye the user of the document.

philipad
11-10-2008, 10:51 PM
this the document

OTWarrior
11-11-2008, 02:04 AM
Try this...

NB: It will work once when you choose the dropdown, then you have to move out of the box to allow the code to fire again. This is a slight quirk I have found with the onEntry and OnExit macros that they only fire when you leave the formfield, whereas here you want it to work "onChange", which simply doesn't exist. With this code, it kind of turns it into onChange, except it only works the once until you leave the object and return to it.

fumei
11-12-2008, 11:26 AM
philipad, my demo did, in fact, demonstrate. A choice executed something. Whether it is displaying a messagebox, or putting text into a bookmark is irrelevant.

You must be clear as possible when you ask questions. Your document has the second item as a formfield. It is not a bookmark (although formfields HAVE bookmarks). In other words, what you want - but do not say - is the choice in dropdown_1 to change the default (displayed) value in another formfield.

Which of course can be done, but you need to actually state what it is you want. I have to ask WHY you want to do this. The second dropdown is, a dropdown. It has choices. WHY do you want a "two" selected in formfield1, to make "2" in formfield2?

Is it acceptable then to have "two" in formfield1, and "5" in formfield2? because, as it stands, that is absolutely possible. In other words, if there is a relationship between "two" and "2" - between the two formfields - as it stands, you are NOT maintaining that relationship. The user can change it.

You can use an Change event - so any changes to a dropdown immediately change text somewhere else, IF you use an ActiveX control, rather than a formfield.

In the demo attached, the choice selected in the ComboBox immediately changes the text of a bookmark - not a formfield. This is done via the _Change event of the control.Option Explicit
Public OnOpen As Boolean


Private Sub ComboBox1_Change()
Dim OtherStuff()
Dim strOut As String

OtherStuff = Array("1", "2", "3", "4")

If OnOpen = True Then
Call FillABookmark("here", "")
Else
strOut = OtherStuff(ComboBox1.ListIndex)
Call FillABookmark("here", strOut)

End If
OnOpen = False
End SubNote the use of the OnOpen variable. Unless you actually want the default text of the bookmark to be "1", you need to clear the bookmark text - make it "".

This is because just opening a document fires all ActiveX control _Change events. And THAT is why ActiveX controls are linked to Security. Just the existence of an ActiveX control in a document executes code.

NOTE: if your Security is High, then ActiveX controls will NOT function.