Defining Values From Checkboxes

StacyStacy

A "Californian" at heart!
Local time
Today, 01:54
Joined
Jan 29, 2003
Messages
159
Here's an easy one?

How do you define a value chosen from a check box?
Example: If I had 3 checkboxes in my form and someone chose the 1st one for apples, how do I show 'apples' in my table instead of '1'?

Thanks
 
Somebody correct me if need be here. You don't need your table to show apples. Tables hold the values to show on your forms and reports. If you want the selection to be restricted to only one choice, try an option group instead of checkboxes.
 
You can use some code in the After Update event of the checkboxes, but I wouldn't do that. Instead, I'd suggest two things.

Perhaps you can use an option group (like a bunch of radio buttons) for selecting the value (since we are talking about just a single value). What do you store in the field if the user selects two of the three checkboxes? Best to use the option group control wizard to help you construct this.

Second, you're better off storing the numeric result of the option group rather than text like "apples" or "oranges" - it takes up less space in your database. You can easily create a table of choices that correspond to the numeric possibilities and include the table in any queries.
 
Using a Checkbox, you can't, but if you want to have the value of the checkbox (1 or 0) to show up in a report, Use the "Switch" function in the Format event.

Switch (checkbox = 1, "Apples", checkbox =0, "Beans")
 
I think Batman's answer is close to what I am looking for. I'm not concern with the values stored in the tables. I am only concerned with the ones printed on the actual report, which should reflect 'apples', not '1'.

How do I write code to show on report to specify 'apples' vs '1'?

thanks, ;)
 
When there is a definite 1,2,3 sequence, such as there would be with an option group, the Choose() function is much simpler to use. Here are some examples from the debug window.

j = 1
x = choose(j, "Apples", "Bananas", "Oranges")
? x
Apples
j = 2
x = choose(j, "Apples", "Bananas", "Oranges")
? x
Bananas
j = 3
x = choose(j, "Apples", "Bananas", "Oranges")
? x
Oranges
 
Would you walk me through in setting that up. I am unsure as to how I would do that whereby it will ONLY show up on a report.
 
Stacy-

This is becoming rather murky. Would you please give a few more details as to how your form relates to your report.

Bob
 
Stacy, you might want to use a combobox rather than checkboxes. You want to allow only a single item to be selected therefore, you should use a graphical element that only allows a single item to be selected. You should not use three separate controls when the selection is mutually exclusive. Your interface will be confusing to your users. You can populate the combo with a value list or by binding its rowsource to a table or query.
 

Users who are viewing this thread

Back
Top Bottom