Checked and Uncheck checkboxes with code

  • Thread starter AnhCVL via AccessMonster.com
  • Start date
A

AnhCVL via AccessMonster.com

Hi all,

I have a form which have couple checkboxes. which is Yes & No checkboxes so I
want the the Yes box to be uncheck automatically when I check the No box and
vice versa. Each of the checkbox is bound to a yes/no field in the database
table, I've try to used the code below:

Private Sub Check50_Click()
If Check50.Checked = False Then
Check50.Checked = True
Check52.Checked = False
End If

End Sub

If Check52.Checked = False Then
Check52.Checked = True
Check50.Checked = False
End If


where as check50 is YES and check52 is NO. I was thinking of put an array
checkboxes but not sure if it's correct way. any help will be greatly
appreaciated.

Thanks.
 
O

OldKingCole

Hi all,

I have a form which have couple checkboxes. which is Yes & No checkboxes so I
want the the Yes box to be uncheck automatically when I check the No box and
vice versa. Each of the checkbox is bound to a yes/no field in the database
table, I've try to used the code below:

Private Sub Check50_Click()
If Check50.Checked = False Then
Check50.Checked = True
Check52.Checked = False
End If

End Sub

If Check52.Checked = False Then
Check52.Checked = True
Check50.Checked = False
End If

where as check50 is YES and check52 is NO. I was thinking of put an array
checkboxes but not sure if it's correct way. any help will be greatly
appreaciated.

Thanks.

Use the BeforeUpdate event on each checkbox;

Private Sub Check50_BeforeUpdate(Cancel As Integer)

Me.Check52=NOT(Me.Check50)

End Sub

Private Sub Check52_BeforeUpdate(Cancel As Integer)

Me.Check50=NOT(Me.Check52)

End Sub
 
A

AnhCVL via AccessMonster.com

Thank you very much for the info. One more question, what if I have 3 or 4
checkboxes, can the code work as well?


[quoted text clipped - 24 lines]
Use the BeforeUpdate event on each checkbox;

Private Sub Check50_BeforeUpdate(Cancel As Integer)

Me.Check52=NOT(Me.Check50)

End Sub

Private Sub Check52_BeforeUpdate(Cancel As Integer)

Me.Check50=NOT(Me.Check52)

End Sub
 
A

AnhCVL via AccessMonster.com

Nevermind, I got it to work. Thanks for everything!
Thank you very much for the info. One more question, what if I have 3 or 4
checkboxes, can the code work as well?
[quoted text clipped - 15 lines]
 

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