Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Click event executing on more than just a click!

Status
Not open for further replies.

rickyoswaldiow

Programmer
Jul 16, 2007
127
GB
Morning all. On my form today I have a checkbox that can enable or disable a combo box. For this I am using the Click event of the checkbox then an If statement to check its own state and enable/disable the combo. I have a problem however - this check box is also toggled by another event (it's reading data from a recordset) and this also seems to trigger the Click event! I only want the event to trigger if the user actually clicks it with the mouse - I have tried MouseUp and Down... Any ideas?
 
We have discussed a work around for this problem in the office. When the function that reads from the recordset is running, a boolean is toggled (blnScattering). On the click event of the check box, if blnScattering is true, the event won't trigger - if it is false, it will trigger. Should work fine, I'm about to code it.
 
Code:
blnScattering = True

With rsRecordSet
   Me.txtSomeText = !SomeText
   Me.chkSomeCheck = !SomeCheck
End With

blnScattering = False

___________________________________________________

Private Sub chkWarehouseOffSite_Click()
    If blnWarehouseScattering = False Then
        If Me.chkWarehouseOffSite = 1 Then Me.cboWarehouseDespatchAddress.Enabled = True
        If Me.chkWarehouseOffSite = 0 Then Me.cboWarehouseDespatchAddress.Enabled = False
    End If
    
End Sub

As you can see, the statement wont trigger if the check box is triggered by the recordset populating controls.
 
It's actually fairly common to use a boolean variable to disable event handling code when an event is triggered by code and you don't want the handling code to execute. You've described the technique quite well. :)
 
May be I am confusing further, but don't we have a Value Changed event?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top