Make checkboxes invisibile based on combo box selection

T

TinaR

I'm working with Access 2007.
I have a combo box on my form with three items to choose from in the drop
down. I then have two check boxes that I want to be visibile only if the
user selects the 2nd or 3rd item in the drop down. If they choose the first
item in the drop down, I want the check boxes to disappear. I put my IF
Statement in the combo box's AfterUpdate event. It works except that the
checkboxes are either visibile or not visible in ALL of the records. How do
I keep the checkboxes visible or invisible for each record? Not sure what
I'm doing wrong. Below is my code:

Private Sub cbo1_AfterUpdate()
If.Me.cbo1 <> "Item1" Then
Me.Label1.Visibile = True
Me.ck1.Visible = True
Me.Label2.Visibile = True
Me.ck2.Visibile = True
Else
Me.Label1.Visibile = False
Me.ck1.Visible = False
Me.Label2.Visibile = False
Me.ck2.Visibile = False
End If
End Sub

Thanks for your help!
Tina
 
B

Barry A&P

Tina

try this in the form current event to help when navigating between records..

Private Sub Form_Current()
cbo1_AfterUpdate
End Sub

Barry
 
T

TinaR

That works great! Thank you. Just out of curiosity, can you tell me why it
works?
Tina
 
B

Barry A&P

Tina
Im new to access and i pulled my hair out for a long time about it. but here
is what happens.

when you change your combo1 the after update event fires and does what you
told it to do, so it hides or shows controls.

the controls hidden property has nothing to do with what data is in it so
when you navigate to a different record the control is still hidden..

the forms on current event fires after navigation or load or some other
stuff im not sure about but when ever it fires we want to say hey Fire
the cbo1_AfterUpdate so that the control properties are correct for the
Currently displayed record..

even though we didnt change combo1 we still want to run its code because the
data displayed in combo1 may be different

Hope this helps
Barry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top