check checkbox status

matt09524

Freshman
Joined
Sep 14, 2005
Messages
47
This problem is simple and yet the answer eludes me.

I have a custom procedure that I call on the formload. basically if the checkbox is checked, then disable all the buttons, else enable them all. This seems to work when the form loads, it is unchecked. but when I check it again, the buttons are still enabled. I have a similar thing on the main form, except it will constantly check and do what the entire if then statement says.

What am I doing wrong? code below

Code:
Private Sub DefaultCheck()
        If ckdefault.Checked = True Then
            emlclr.Enabled = False
            navclr.Enabled = False
            sysclr.Enabled = False
            ctrlclr.Enabled = False
            frmclr.Enabled = False
            infoclr.Enabled = False
            lblbkclr.Enabled = False
        Else
            emlclr.Enabled = True
            navclr.Enabled = True
            sysclr.Enabled = True
            ctrlclr.Enabled = True
            frmclr.Enabled = True
            infoclr.Enabled = True
            lblbkclr.Enabled = True
        End If
    End Sub

I call this sub in the Form_load.
 
matt09524 said:
This problem is simple and yet the answer eludes me.

I have a custom procedure that I call on the formload. basically if the checkbox is checked, then disable all the buttons, else enable them all. This seems to work when the form loads, it is unchecked. but when I check it again, the buttons are still enabled. I have a similar thing on the main form, except it will constantly check and do what the entire if then statement says.

What am I doing wrong? code below

Code:
Private Sub DefaultCheck()
        If ckdefault.Checked = True Then
            emlclr.Enabled = False
            navclr.Enabled = False
            sysclr.Enabled = False
            ctrlclr.Enabled = False
            frmclr.Enabled = False
            infoclr.Enabled = False
            lblbkclr.Enabled = False
        Else
            emlclr.Enabled = True
            navclr.Enabled = True
            sysclr.Enabled = True
            ctrlclr.Enabled = True
            frmclr.Enabled = True
            infoclr.Enabled = True
            lblbkclr.Enabled = True
        End If
    End Sub

I call this sub in the Form_load.

Hi

Are you saying that when you 'Check' the ckdefault checkbox at design time and then run the application that the code fails or when you click the ckdefault check box at run time?

If the answer is run time are you calling the 'DefaultCheck' procedure from the CheckChanged event?

You could also use less lines of code like this:

emlclr.Enabled = Not ckdefault.Checked
navclr.Enabled = Not ckdefault.Checked
sysclr.Enabled = Not ckdefault.Checked
ctrlclr.Enabled = Not ckdefault.Checked
frmclr.Enabled = Not ckdefault.Checked
infoclr.Enabled = Not ckdefault.Checked
lblbkclr.Enabled = Not ckdefault.Checked

Cheers
CM :rolleyes:
 
At run time, if I change the status of ckdefault it does not execute the conditions. I can see why it's doing this, but I don't see how I can keep the script active without getting myself into a neverending loop or something.

What's weird is that I have something like this in another place in my app and i don't have a problem with it :(
 
One thought is to either put the DefaultCheck code in the check box's click sub or call the DefaultCheck sub from the check box's click sub as code mechanic suggested.
 
Back
Top