help with checkboxes...

G

Guest

Good Day all,

I am setting up a form for mileage tracking that would include two
checkboxes "One Way" and "Round Trip" The first question that I have is that
I would like the option to only have one check box checked at any one point,
so if "one way " is checked then "round trip is unchecked. I would like to
use an Option group but don't know how? I have One way set up so that if it
is checked, then my "total milage" text box is the tripmilage, and if
"roundtrip" is checked then the "totalmilage" is tripmilage * 2", can anyone
help?

Thanks,

Brook
 
W

Wayne Morgan

Normally, if only one can be selected, a Radio Button is used instead of a
checkbox, but they will both get the job done in an option group. To set up
an option group, open the form in design view. Click on the Option Group
button on the toolbox and place the option group on the form. It will look
like a rectangle with a label. To add controls to the option group, select
the desired control in from the toolbox (checkbox or radio button) and drop
it on the option group. You should see the option group become highlighted
as the mouse moves over it. This is your clue that if you drop the control
now, it will be made part of the option group. The "value" will now come
from the option group, not the controls on it when you refer to these in
other controls or code.

Depending on where you are using this, one option to use the option group to
control the result would be this calculation:

=IIf([optOptionGroup]=1, [TripMilage], [TripMilage] * 2)

There is no need for an embedded IIf if the option group can't be Null. If
it can be Null, then you would need to change the above to:

=IIf([optOptionGroup]=1, [TripMilage], IIf([optOptionGroup]=2, [TripMilage]
* 2))

If you set a Default Value for the option group, it won't be Null since
there is no way to deselect both options simultaneously once one of them has
been selected.
 
G

Guest

Hello Wayne,

Thanks for the info, I set up an OptionGroup called "traveloptions" with
Option1 ("One Way") Option2 ("Round Trip").

I am unclear on where to add the code, do I add the code as the textbox
"TripMilage" control source? or to an event within the OptionGroup itself?



=IIf([traveloption]=1, [TripMilage], IIf([traveloption]=2, [TripMilage]

Any suggestions?

Thanks,

Brook

Wayne Morgan said:
Normally, if only one can be selected, a Radio Button is used instead of a
checkbox, but they will both get the job done in an option group. To set up
an option group, open the form in design view. Click on the Option Group
button on the toolbox and place the option group on the form. It will look
like a rectangle with a label. To add controls to the option group, select
the desired control in from the toolbox (checkbox or radio button) and drop
it on the option group. You should see the option group become highlighted
as the mouse moves over it. This is your clue that if you drop the control
now, it will be made part of the option group. The "value" will now come
from the option group, not the controls on it when you refer to these in
other controls or code.

Depending on where you are using this, one option to use the option group to
control the result would be this calculation:

=IIf([optOptionGroup]=1, [TripMilage], [TripMilage] * 2)

There is no need for an embedded IIf if the option group can't be Null. If
it can be Null, then you would need to change the above to:

=IIf([optOptionGroup]=1, [TripMilage], IIf([optOptionGroup]=2, [TripMilage]
* 2))

If you set a Default Value for the option group, it won't be Null since
there is no way to deselect both options simultaneously once one of them has
been selected.

--
Wayne Morgan
MS Access MVP


Brook said:
Good Day all,

I am setting up a form for mileage tracking that would include two
checkboxes "One Way" and "Round Trip" The first question that I have is
that
I would like the option to only have one check box checked at any one
point,
so if "one way " is checked then "round trip is unchecked. I would like to
use an Option group but don't know how? I have One way set up so that if
it
is checked, then my "total milage" text box is the tripmilage, and if
"roundtrip" is checked then the "totalmilage" is tripmilage * 2", can
anyone
help?

Thanks,

Brook
 
G

Guest

Thank you very much!

Brook

Wayne Morgan said:
It would be the control source for the trip mileage textbox.

--
Wayne Morgan
MS Access MVP


Brook said:
Hello Wayne,

Thanks for the info, I set up an OptionGroup called "traveloptions" with
Option1 ("One Way") Option2 ("Round Trip").

I am unclear on where to add the code, do I add the code as the textbox
"TripMilage" control source? or to an event within the OptionGroup itself?



=IIf([traveloption]=1, [TripMilage], IIf([traveloption]=2, [TripMilage]))
 

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