Required if Other is used in CboBox

S

SoggyCashew

Hello, I have a combo box cbo1 that has some choices in it and one of them is
called "Other". My question is if someone chooses "Other" from the combo box
how could I get a pop up msg to come up that says something like "If other is
used as a choice then you must give a reason why" and have it set focus to a
text box named text1. The msg box would have something else like OK and
cancel and if canceled then it would clear cbo1 and fill text3 with a zero
then set focus to text1. How would I do this?
 
P

Philip Herlihy

SoggyCashew said:
Hello, I have a combo box cbo1 that has some choices in it and one of them is
called "Other". My question is if someone chooses "Other" from the combo box
how could I get a pop up msg to come up that says something like "If other is
used as a choice then you must give a reason why" and have it set focus to a
text box named text1. The msg box would have something else like OK and
cancel and if canceled then it would clear cbo1 and fill text3 with a zero
then set focus to text1. How would I do this?

SoggyCashew - are you some kind of nut?

Not too difficult - just put some code in the AfterUpdate event handler
for the combo box. Instead of a msgbox, you could have a label,
normally hidden, turn visible - a bit less "in your face".

You could also check that there is something in the "reasons" box by
putting code in the BeforeUpdate event handler for the form, or possibly
the "lost focus" event handler for the "reasons" box itself.

Phil, London.
 
P

Philip Herlihy

SoggyCashew said:
Thanks Philip for the ideas! Some sample code would help alot :)


I'm not going to write it for you, but try this:

Put a label on your form, with caption "Give reason" (or whatever).
Using the property sheet, colour it red, and make it invisible. Name it
labelWarning. You'll have a text box called txtReason to accept the input.

Now look at the properties for your combo, and go to the Events tab.
Click the "builder" button at the far right of the AfterUpdate event,
and choose "Code Builder". Up comes the VBA environment.
Save yourself some real grief by adding some error handling code inside
the routine where the cursor has landed, as I've done here, surrounding
the two lines that do the work:

Private Sub Combo0_AfterUpdate()
On Error GoTo bust:
Me!labelWarning.visible = true
Me!txtReason.SetFocus
Exit Sub
bust:
MsgBox Err.Description, vbOKOnly, "Combo0_AfterUpdate"
End Sub

You'll want to set the label's visible property to False at an
appropriate point too.

Phil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top