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!

Doubt in setting the value of a checkbox... Urgent 1

Status
Not open for further replies.

arunmd1

Programmer
Mar 20, 2008
24
FR
Hi guys,
I need a help.I am creating a tool in excel using VBA. There i have some checkboxes to initiate some actions. I have also provided a command button( Clear ) to clear that cases. The actions to be performed when the user switch on or switch off the checkbox is different. But if the user click the "CLEAR" button after doing the desired actions it has to uncheck the checkbox .( that is setting its value to false). I tried it using
"Checkbox1.value = false"
But once the value is set false, the control is going to the function "Checkbox1_activate" which brings in unwanted actions. Provide a solution plz. Its urgent.
 
There's probably a much more elegant way to do this but if you're looking for ideas then why not set a global boolean variable = true when you click the clear button. Now on your checkbox_activate function test for this global variable. If its true do nothing except reset it to false. if its false do what it would normally do.


In order to understand recursion, you must first understand recursion.
 
Hi. A changed the logic in my program slightly and amazingly the program is working fine. Anyway thanks a lot for ur ideas Mr.taupirho.
 




Hi,

In your ClearCheckboxes procedure, turn OFF Events before clearing and then restore Events.
Code:
application.enableevents=false
'do stuff
application.enableevents=true


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Hi Skip ,
I think the idea enableevents = false and then do stuff and then enableevents = true is not working.I checked it now .Try this snippet , it is entering an infinite loop.
The control is not at all reaching the line application.enableevents = true.


Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
MsgBox True
Application.EnableEvents = False
CheckBox1.Value = False
Application.EnableEvents = True
Else
MsgBox False
Application.EnableEvents = False
CheckBox1.Value = True
Application.EnableEvents = True
End If
End Sub
 




Try this.

Use a Button to clear all...
Code:
Public bEvents As Boolean
Private Sub CheckBox1_Click()
    If bEvents Then
        MsgBox "check 1"
    End If
End Sub

Private Sub CommandButton1_Click()
'uncheck all boxes
    Dim shp As Shape
    If CheckBox2.Value Then
    bEvents = False
        For Each shp In Sheet1.Shapes
            Select Case Left(shp.Name, 5)
                Case "Check"
                    shp.OLEFormat.Object.Object.Value = False
            End Select
        Next
    bEvents = True
    End If
End Sub

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 





Sorry, I posted the wrong code...
Code:
Public bEvents As Boolean
Private Sub CheckBox1_Click()
    If bEvents Then
        MsgBox "check 1"
    End If
End Sub

Private Sub CommandButton1_Click()
'uncheck all boxes
    Dim shp As Shape
    bEvents = False
    For Each shp In Sheet1.Shapes
        Select Case Left(shp.Name, 5)
            Case "Check"
                shp.OLEFormat.Object.Object.Value = False
        End Select
    Next
    bEvents = True
End Sub


Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top