Checkbox validation

G

Guest

I have an existing Access 2003 database with yes/no checkboxes with some of
the forms. Changing the checkboxes to option values is not a viable option
due to the number of queries and reports that are already based upon them.

If I have three separate checkbox controls on a form [yes] [no] [na], is
there a way to create some sort of validation rule or code that would allow
only one of these yes/no boxes to be checked at a time? Right now all three
can be checked independently.
 
C

Carl Rapson

Don said:
I have an existing Access 2003 database with yes/no checkboxes with some of
the forms. Changing the checkboxes to option values is not a viable option
due to the number of queries and reports that are already based upon them.

If I have three separate checkbox controls on a form [yes] [no] [na], is
there a way to create some sort of validation rule or code that would
allow
only one of these yes/no boxes to be checked at a time? Right now all
three
can be checked independently.

You could code each checkbox's AfterUpdate event and clear the other
checkboxes if this one is checked:

Private Sub chkCheck1_Click()
If Me.chkCheck1 = True Then
Me.chkCheck2 = False
Me.chkCheck3 = False
End If
End Sub


Carl Rapson
 
G

Guest

I use the following code:

Private Sub chk1_BeforeUpdate(Cancel As Integer)
If Me.chk1 = False And Me.chk2 = False And Me.chk3 = False Then
Cancel = True
End If
End Sub

Private Sub chk2_BeforeUpdate(Cancel As Integer)
If Me.chk1 = False And Me.chk2 = False And Me.chk3 = False Then
Cancel = True
End If
End Sub

Private Sub chk3_BeforeUpdate(Cancel As Integer)
If Me.chk1 = False And Me.chk2 = False And Me.chk3 = False Then
Cancel = True
End If
End Sub

Private Sub chk1_AfterUpdate()
If Me.chk1 = True Then
Me.chk2 = False
Me.chk3 = False
End If
End Sub

Private Sub chk2_AfterUpdate()
If Me.chk2 = True Then
Me.chk1 = False
Me.chk3 = False
End If
End Sub

Private Sub chk3_AfterUpdate()
If Me.chk3 = True Then
Me.chk1 = False
Me.chk2 = False
End If
End Sub

The before update code insures you can't uncheck a box when none of the
others is checked.
The afterupdate code clears the other two boxes when a check box is checked
true.
 
G

Guest

Works great. I envy those of you who can make something seem so complicated
be so simple. Your great.
--
Thanks!


Carl Rapson said:
Don said:
I have an existing Access 2003 database with yes/no checkboxes with some of
the forms. Changing the checkboxes to option values is not a viable option
due to the number of queries and reports that are already based upon them.

If I have three separate checkbox controls on a form [yes] [no] [na], is
there a way to create some sort of validation rule or code that would
allow
only one of these yes/no boxes to be checked at a time? Right now all
three
can be checked independently.

You could code each checkbox's AfterUpdate event and clear the other
checkboxes if this one is checked:

Private Sub chkCheck1_Click()
If Me.chkCheck1 = True Then
Me.chkCheck2 = False
Me.chkCheck3 = False
End If
End Sub


Carl Rapson
 
C

Carl Rapson

To be honest, most of it comes from doing what you just did - coming here
and asking questions. It's a great way to learn.

Carl Rapson

Don said:
Works great. I envy those of you who can make something seem so
complicated
be so simple. Your great.
--
Thanks!


Carl Rapson said:
Don said:
I have an existing Access 2003 database with yes/no checkboxes with some
of
the forms. Changing the checkboxes to option values is not a viable
option
due to the number of queries and reports that are already based upon
them.

If I have three separate checkbox controls on a form [yes] [no] [na],
is
there a way to create some sort of validation rule or code that would
allow
only one of these yes/no boxes to be checked at a time? Right now all
three
can be checked independently.

You could code each checkbox's AfterUpdate event and clear the other
checkboxes if this one is checked:

Private Sub chkCheck1_Click()
If Me.chkCheck1 = True Then
Me.chkCheck2 = False
Me.chkCheck3 = False
End If
End Sub


Carl Rapson
 

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