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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkbox Clear

Status
Not open for further replies.

tirany

Technical User
Nov 26, 2002
2
US
I want the user to be able to clear the screen by using a command button, but I can't seem to get the code right for the checkboxes. Also, when a checkbox is deselected, it won't take the value it was assigned away. If the checkbox is selected again, it just adds more to the value. Can anybody help? Please and thank-you in advance.
This is my code for the checkboxes:

'If checked add dollar amount to total
If chkHotTub.Value = vbChecked Then
curHotTub = 25
Else
curHotTub = 0

End If
 
The basic problem that you're running into is that programatically setting the value of checkbox fires the click event, just as if the checkbox were clicked by the user.

One approach that I have used is to set up a form level variable to control when the click event code is to be executed.

In the Declarations section of the form add the following line:

Dim fBol_DoCheckEvent as Boolean

then initialize this event to TRUE in the form load.

The Click Event would then look something like the following:

Sub ChkCheckBox_Click ()

If (fBol_DoCheckEvent = True) Then
... do what you need to do here
End If

End Sub

At other points in the program, where you want to set the value of checkbox but do not want the event executed assign false to the variabled, set the checkbox, then reset the variable

fBol_DoCheckEvent = False
chkCheckBox.Value = vbChecked
fBol_DoCheckEvent = True

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top