From the BeforeUpdate event of a combo-box, I am calling a public sub-routine that checks the validity of the selection based on other selections on the form. If the selection is bad, the public sub should show a msgbox and cancel the combo-box selection (return it to its previous selection).
Well, the msgbox appears but the event doesn't cancel. Can anyone help?
Here's the snippet:
'On bad combination, alert user and deny change
MsgBox ("You have selected an improper combination of Run Type and Vehicle Type" & vbCrLf & "(You can't have that car do that type of run)" & vbCrLf & "Your selection will be reset")
The BeforeUpdate event uses the Cancel variable. All you have to do is set Cancel = True and the event will be cancelled. Keep in mind that it is not like an exit, any code after Cancel=True will be executed. So you might actually need and Exit or and If to skip any code after the validity check.
For Teddy...the difference is that I wanted to cancel the updatingof the field to the value selected by the user. You were suggesting something that would just cancel the sub-routine that was triggered by the event.