|
-
May 17th, 2000, 08:33 AM
#1
Problem with recursive click event.
After a selection made from a combo box I want to check to see if certain conditions are met if not I want to reset the combo box to force the user to make the appropriate selection. Then problem is that when I reset the combo box it triggers the click event again and I get a repeat of the test and the message. Is there a way to turn off the event checking for the combo box while I reset it.
Private Sub cmboTest_Click()
If condition Then
msgrtn = MsgBox("Incorrect selection made", vbOKOnly)
cmboTest.ListIndex = -1
Exit Sub
End If
End sub
-
May 17th, 2000, 10:58 AM
#2
Addicted Member
This should work for you. In this example I put a combobox on a form with the values 1,2,3, and 4 in the list property. Of course your data and condition for checking will be different.
In this example the condition is the number "3" on the list is the only valid choice. All other selections cause a reset. The boolean flag causes the code in the combobox click event to be skipped if the reset flag is set to true.
Hope this helps.
Code:
'Put these in the General Declarations part
Option Explicit
'blnCboReset is a flag to indicate combo box is being reset
Private blnCboReset As Boolean
Private Sub Form_Load()
'initialize combobox reset flag
blnCboReset = False
End Sub
Private Sub Combo1_Click()
If Not blnCboReset Then
If Combo1.Text <> "3" Then
MsgBox "Incorrect selection made", vbInformation & vbOKOnly, "Try Again"
'bad selection so set flag
blnCboReset = True
'This triggers click event again.
Combo1.ListIndex = -1
'flag reset to allow next user selection.
blnCboReset = False
Exit Sub
Else
MsgBox "Good Choice", vbOkOnly, "You Did It!"
End If
End If
End Sub
-
May 17th, 2000, 11:09 AM
#3
Thanks John
I was thinking of something along the lines of the solution you offered but more as a last resort. I have numerous situations in where the same problem will occur. Therefore I was hoping for a more automatic solution like setting some property etc.
-
May 17th, 2000, 07:10 PM
#4
Instead of the
Private blnCboReset As Boolean
You could make it a static variable and put it in the sub, that way you cant accidently change it.
Code:
Private Sub Combo1_Click()
Static blnCboReset As Boolean
-
May 17th, 2000, 11:04 PM
#5
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|