Using a check box to set the value of a string variable

J

Jim McBride

I am very new to using Access. I need to create a field on a form that is a
check box. If the box is checked, I want the underlying field to be set to a
string value. If the box is not checked, I want that string value to be
blank. Can I do this using the Expression Builder, and if so, how??
 
J

Jeff Boyce

Jim

If you are saying that a "check" is the same as "some fixed string value"
and "unchecked" is "" (an empty/zero length string), then why bother? A
checkbox (Yes/No) should be sufficient.

If you are trying to use a table to help you generate a report, use a query
against the table and set the value of the string based on the value in the
checkbox field.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
F

fredg

I am very new to using Access. I need to create a field on a form that is a
check box. If the box is checked, I want the underlying field to be set to a
string value. If the box is not checked, I want that string value to be
blank. Can I do this using the Expression Builder, and if so, how??

Add a check box field to your table.
Include the check box field on your form.

When clicked, the value of the check box field is -1.
That's all you need store.

There are several ways to then show a string value when the check box
is checked. Here's one:
Where ever you wish to show a string value, i.e. "Payment received",
simply use an unbound control (on a form or on a report).
Set it's control source to:

=IIf([CheckField] = -1,"Payment Received","")
 
J

Jim McBride

Thank you so much for the quick answer! Actually, this is not a report, but
I want the check box on the form to dictate what will be placed in the string
field in the table. If the box is checked, the string field will get the
string "ud.bmp" (a picture that will be displayed on the label) and if the
box is cleared, the string field will be blank.
 
J

Jeff Boyce

The point we're trying to make is that it is unnecessary and redundant to
use both the checkbox and the string.

If you want to have an image on the form, it sounds like it will ALWAYS be
the same image, if the checkbox is checked.

So why not put a small expression in the checkbox's AfterUpdate event that
"names" the image if checked, and clears the name if unchecked?

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
Top