Simulated option group problem

G

Guest

I wanted to see if I can get the functionality of an option group by
programming check boxes [check box "Answer" is bound to a yes/no field, and
check box "CheckNo" is unbound], and it is indeed possible and pretty simple
- I just attached a couple of lines of code to the AfterUpdate event of both
check boxes so that when one is checked, the other becomes unchecked.

The problem I have is that when I load the form, and the bound form is
checked, the unbound form is not empty. I was trying to use the code below to
clear the field if necessary, but it's not producing the desired result, ie
when the default value of the check box was "true", it was checked even when
the other check box was checked, and now that there's no default value, it's
grey instead of white.
What needs to


Private Sub Form_Load()

If Answer = -1 Then
CheckNo = 0

End If

End Sub
 
M

Matthias Klaey

Niniel said:
I wanted to see if I can get the functionality of an option group by
programming check boxes [check box "Answer" is bound to a yes/no field, and
check box "CheckNo" is unbound], and it is indeed possible and pretty simple
- I just attached a couple of lines of code to the AfterUpdate event of both
check boxes so that when one is checked, the other becomes unchecked.

The problem I have is that when I load the form, and the bound form is
checked, the unbound form is not empty. I was trying to use the code below to
clear the field if necessary, but it's not producing the desired result, ie
when the default value of the check box was "true", it was checked even when
the other check box was checked, and now that there's no default value, it's
grey instead of white.
What needs to


Private Sub Form_Load()

If Answer = -1 Then
CheckNo = 0

End If

End Sub

Why don't you use a regular option group? You can use radio buttons,
check boxes or toggle buttons. You see this if you create an option
group with the controls wizard. To change your existing design to an
option group, first insert an empty frame (without using the controls
wizard) on the form, then select the check boxes, cut then, select the
frame, and paste.

Perhaps you can solve then your problem (which I don't clearly
understand: are there two forms involved?) by using the control source
of the option group.

HTH
Matthias Kläy
 
G

Guest

Thank you for your reply.

I'm using this method because I have a checkbox in a continuous subform, and
I couldn't get an option group to work with that.
But I managed to solve my problem - simply by moving the code to the
OnCurrent event.

Thank you for trying to help though, I appreciate it.


Matthias Klaey said:
Niniel said:
I wanted to see if I can get the functionality of an option group by
programming check boxes [check box "Answer" is bound to a yes/no field, and
check box "CheckNo" is unbound], and it is indeed possible and pretty simple
- I just attached a couple of lines of code to the AfterUpdate event of both
check boxes so that when one is checked, the other becomes unchecked.

The problem I have is that when I load the form, and the bound form is
checked, the unbound form is not empty. I was trying to use the code below to
clear the field if necessary, but it's not producing the desired result, ie
when the default value of the check box was "true", it was checked even when
the other check box was checked, and now that there's no default value, it's
grey instead of white.
What needs to


Private Sub Form_Load()

If Answer = -1 Then
CheckNo = 0

End If

End Sub

Why don't you use a regular option group? You can use radio buttons,
check boxes or toggle buttons. You see this if you create an option
group with the controls wizard. To change your existing design to an
option group, first insert an empty frame (without using the controls
wizard) on the form, then select the check boxes, cut then, select the
frame, and paste.

Perhaps you can solve then your problem (which I don't clearly
understand: are there two forms involved?) by using the control source
of the option group.

HTH
Matthias Kläy
 
J

James A. Fortune

Niniel said:
I wanted to see if I can get the functionality of an option group by
programming check boxes [check box "Answer" is bound to a yes/no field, and
check box "CheckNo" is unbound], and it is indeed possible and pretty simple
- I just attached a couple of lines of code to the AfterUpdate event of both
check boxes so that when one is checked, the other becomes unchecked.

The problem I have is that when I load the form, and the bound form is
checked, the unbound form is not empty. I was trying to use the code below to
clear the field if necessary, but it's not producing the desired result, ie
when the default value of the check box was "true", it was checked even when
the other check box was checked, and now that there's no default value, it's
grey instead of white.
What needs to


Private Sub Form_Load()

If Answer = -1 Then
CheckNo = 0

End If

End Sub

Try using the form's Current event.

Private Sub Form_Current()
CheckNo.Value = Not Answer.Value
End Sub

'----existing code
Private Sub Answer_AfterUpdate()
CheckNo.Value = Not Answer.Value
End Sub

Private Sub CheckNo_AfterUpdate()
Answer.Value = Not CheckNo.Value
End Sub
'----

I tried this on a form with Answer bound to a Y/N field in a table and
CheckNo unbound. It seemed to work.

James A. Fortune
(e-mail address removed)
 
G

Guest

Oh yes, that works as well. And it requires only 1 line of code. Very cool.
Thank you.

James A. Fortune said:
Niniel said:
I wanted to see if I can get the functionality of an option group by
programming check boxes [check box "Answer" is bound to a yes/no field, and
check box "CheckNo" is unbound], and it is indeed possible and pretty simple
- I just attached a couple of lines of code to the AfterUpdate event of both
check boxes so that when one is checked, the other becomes unchecked.

The problem I have is that when I load the form, and the bound form is
checked, the unbound form is not empty. I was trying to use the code below to
clear the field if necessary, but it's not producing the desired result, ie
when the default value of the check box was "true", it was checked even when
the other check box was checked, and now that there's no default value, it's
grey instead of white.
What needs to


Private Sub Form_Load()

If Answer = -1 Then
CheckNo = 0

End If

End Sub

Try using the form's Current event.

Private Sub Form_Current()
CheckNo.Value = Not Answer.Value
End Sub

'----existing code
Private Sub Answer_AfterUpdate()
CheckNo.Value = Not Answer.Value
End Sub

Private Sub CheckNo_AfterUpdate()
Answer.Value = Not CheckNo.Value
End Sub
'----

I tried this on a form with Answer bound to a Y/N field in a table and
CheckNo unbound. It seemed to work.

James A. Fortune
(e-mail address removed)
 

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