Enabling/Disabling Checkboxes

SodaJim

Registered User.
Local time
Today, 02:16
Joined
Jan 12, 2003
Messages
51
Hello,

Couldn't seem to find similarly related topics so I'm seeking help
from the gurus...

What is the best way to enable/disable 2 checkboxes I have
on a form. Enabling them will be based on which one is
selected or updated...?

If chkBox1 is checked, I would like chkBox2 to be
disabled; however, when I new record is added, the default
setting for chkBox1 is checked/true which I would like to
disable chkBox2. Additionally, if chkBox1 is unchecked it
will enable chkBox2 thus both being enabled. Should
chkBox2 become checked/true, it will disable chkBox1.

That should paint a good picture of what I'm attempting to
accomplish... The code below is what I have currently, but
it changes the form on every record which is not good...

=====================================
Private Sub chkBox2_AfterUpdate()
If chkBox2.Value = True Then
chkBox1.Enabled = False
Else
chkBox1.Enabled = True
End If
End Sub


Private Sub chkBox1_AfterUpdate()
If chkBox1.Value = True Then
chkBox2.Enabled = False
Else
chkBox2.Enabled = True
End If
End Sub
=====================================

Any direction appreciated,
Jim
 
Try double clicking checkbox 2 to open the properties and set the default value to zero.

Also, you may want to consider using an option box, where you can only have one selection active at any given time.
 
I thought about an Option Group but the two checkboxes are actually unrelated...
chkBox1 is for items "In Service" or Not; while chkBox2 is for items that have been "Terminated". So, items that have been terminated should not have the ability to check the checkbox "In Service" or Not.

Perhaps I can place the code in the event OnCurrent of the form...
 
Last edited:
Jim,

Let me guess ... your form is a continuous form.

Is that what you mean when you say it changes it for the
whole form?

That is the nature of continues forms.

I'll find a thread that might help you.

Wayne
 
Thanks for the reply Wayne!

However, since there are subforms involved, it's set to single form view...

So, is there a way to control each record's state for the two checkboxes and only change the current record on the form without effecting all the form records...?

Thanks again!!!
 
Jim,

That's much better, have you looked at the form's OnCurrent event?

Wayne
 
I'll slightly modify the code samples into one snippet and place it into the form's OnCurrent Event and see what the results are...
I'll report back with my findings...

Thanks again!
 
Jim,

The form's OnCurrent event should restrict it to only the current
record.

Let me know.

Wayne
 
Hello Wayne,

The form's "Current" Event did the job!
I did have to keep the checkbox's "After_Update" Event with the same code in the event either checkbox needed to be updated...

Question though... Since there's redundant code(just a few lines), would it be possible or even worth the effort to consolidate the code into a module and just call the procedure(s) from Form_Current Event, chkBox1 After_Update Event & chkBox2 After_Update Event...?
 

Users who are viewing this thread

Back
Top Bottom