question regarding checkboxes

L

Lauren B

I am attempting to have the status of a checkbox dictate what appears in a
particular text box. I used to the following code:

If Checkbox = True Then
Textbox = "Comment 1"
Else
Textbox= "Comment 2"
End If
End Sub

I have a problem as a user may uncheck the checkbox; however, "Comment 1"
still needs to appear in the textbox. Is there a way to write my code so
that "Comment 1" appears in the textbox if the checkbox is checked OR was
checked and then unchecked? Comment 2 should only appear if the checkbox
was never checked.

Thank you for any assistance.

LB
 
J

John Vinson

I am attempting to have the status of a checkbox dictate what appears in a
particular text box. I used to the following code:

If Checkbox = True Then
Textbox = "Comment 1"
Else
Textbox= "Comment 2"
End If
End Sub

I have a problem as a user may uncheck the checkbox; however, "Comment 1"
still needs to appear in the textbox. Is there a way to write my code so
that "Comment 1" appears in the textbox if the checkbox is checked OR was
checked and then unchecked? Comment 2 should only appear if the checkbox
was never checked.

You'll need to store the value Comment 1 or Comment 2 in a table in
order for Access to "remember" whether it has EVER been changed.
Remember, a checkbox or a textbox on a form *is not* a data storage
medium - it's a data *display* medium! Data is stored in Tables, and
only in Tables.

That said, you can use code like this to do what you describe. I'm
assuming you're on a Form, with controls chkMyCheck bound to the
yes/no field in your table, and txtComment bound to the comment field.
Select chkMyCheck's AfterUpdate event, click the ... icon by it, and
invoke the Code Builder:

Private Sub chkMyCheck_AfterUpdate()
If Me!chkMyCheck = True Then
Me!txtComment = "Comment 1"
End If
End Sub

If you set the Default Value property of txtComment to "Comment 2" new
records will be set to that value; the AfterUpdate event will
overwrite it if the user checks the checkbox, and leave it alone if
they clear it.

John W. Vinson[MVP]
 

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