update trext field based on check box entry

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have four check boxes called Red, Green, Blue, Yellow and a text Field
called txtColor. Only one of the colors boxes should be checked and whichever
color is checked should be reflected in the text box. Thus if red is checked,
txtColor will be updated to Red.

I thought I had an answer by writing an if statement and putting it on the
After Update event. However I was stumped by two problems:

1) How do I check to make sure that only one check box is checked? This
would be nice but not terribly important.
2) More importantly once an entry has been made to the txtColor field I
don't want it to disappear even if the check mark is removed from the color
field. Thus, in the above example if I remove the checkmark from red for this
record, I would still like txtColor to read Red.

Can this be done? Thank you very much for any help.
 
Elaine said:
I have four check boxes called Red, Green, Blue, Yellow and a text Field
called txtColor. Only one of the colors boxes should be checked and whichever
color is checked should be reflected in the text box. Thus if red is checked,
txtColor will be updated to Red.

I thought I had an answer by writing an if statement and putting it on the
After Update event. However I was stumped by two problems:

1) How do I check to make sure that only one check box is checked? This
would be nice but not terribly important.
2) More importantly once an entry has been made to the txtColor field I
don't want it to disappear even if the check mark is removed from the color
field. Thus, in the above example if I remove the checkmark from red for this
record, I would still like txtColor to read Red.


Those sound like they may be somewhat contradictory
requirements, but I'll take a shot at it.

First, if you only want one check box to be checked, you can
use an Option Group control to contain the check boxes (see
Help for what these do). However, an option group does not
allow you to reset a check box, you can only check a
different option.

To set the text box, use the AfterUpdate event:

Select Case Me.FrameX
Case 1
Me.txtColor = "Red"
Case 2
Me.txtColor = "Green"
Case 3
Me.txtColor = "Blue"
Case 4
Me.txtColor = "Yellow"

You could do this without an option group if there's a good
reason. Use code in each check box's AfterUpdate event
procedure to set all the other check boxes to False. The
AfterUpdate event procedure code for the red checkbox would
be:

If Me.checkboxred = True Then
Me.txtColor = "Red"
Me.checkboxgreen = False
Me.checkboxblue = False
Me.checkboxYellow = False
End If

and it would be similar for the other check boxes.

With all that said and done with, I suggest that you think
about using a combo box instead of all this fooling around.
 
I have four check boxes called Red, Green, Blue, Yellow and a text Field
called txtColor. Only one of the colors boxes should be checked and whichever
color is checked should be reflected in the text box. Thus if red is checked,
txtColor will be updated to Red.

I thought I had an answer by writing an if statement and putting it on the
After Update event. However I was stumped by two problems:

1) How do I check to make sure that only one check box is checked? This
would be nice but not terribly important.
2) More importantly once an entry has been made to the txtColor field I
don't want it to disappear even if the check mark is removed from the color
field. Thus, in the above example if I remove the checkmark from red for this
record, I would still like txtColor to read Red.

Can this be done? Thank you very much for any help.

If you use an Option Group with check boxes, it will only permit one
box at a time to be checked and half your problem is resolved.
Give each option a value of 1,2,3, or 4.

Then code the OptionGroup's AfterUpdate event:
If IsNull([txtColor]) Then
[txtColor] = Choose(OptionGroupName,"Red","Green","Blue","Yellow")
End If


By using separate check boxes you will have to code each one's
AfterUpdate event:
If Me!CheckBoxRed = True then
If IsNull(txtColor) Then
[txtColor] = "Red"
End If
Me!CheckBoxGreen = False
Me!CheckBoxBlue = False
Me!CheckBoxYellow = False
End If

Do similar for each of the other check boxes.
Only if txtColor is null will the color be written to it.
 
Marshall and Fred thank you very much for your replies. On occasion the ticks
in the various check boxes will have to be removed and thus the option group
will not work. However, even when the check marks are removed, I would like
to keep those original entries.

Why not manually enter the color in the checkbox? Once an entry has been
made I don't want the color changed as I will be making some calculations on
it.

Thanks again for your help.

fredg said:
I have four check boxes called Red, Green, Blue, Yellow and a text Field
called txtColor. Only one of the colors boxes should be checked and whichever
color is checked should be reflected in the text box. Thus if red is checked,
txtColor will be updated to Red.

I thought I had an answer by writing an if statement and putting it on the
After Update event. However I was stumped by two problems:

1) How do I check to make sure that only one check box is checked? This
would be nice but not terribly important.
2) More importantly once an entry has been made to the txtColor field I
don't want it to disappear even if the check mark is removed from the color
field. Thus, in the above example if I remove the checkmark from red for this
record, I would still like txtColor to read Red.

Can this be done? Thank you very much for any help.

If you use an Option Group with check boxes, it will only permit one
box at a time to be checked and half your problem is resolved.
Give each option a value of 1,2,3, or 4.

Then code the OptionGroup's AfterUpdate event:
If IsNull([txtColor]) Then
[txtColor] = Choose(OptionGroupName,"Red","Green","Blue","Yellow")
End If


By using separate check boxes you will have to code each one's
AfterUpdate event:
If Me!CheckBoxRed = True then
If IsNull(txtColor) Then
[txtColor] = "Red"
End If
Me!CheckBoxGreen = False
Me!CheckBoxBlue = False
Me!CheckBoxYellow = False
End If

Do similar for each of the other check boxes.
Only if txtColor is null will the color be written to it.
 
Back
Top