Command Buttons in Option Groups

  • Thread starter Thread starter Tony Ford
  • Start date Start date
T

Tony Ford

I have an option group on a form, and I want a command
button within the group to perform an action (open
specific form) when the option is selected, and the
command button is clicked. I already know the option
value numbers of each option within the group. How can I
write the expression that will allow me to do this?

Thanks.
 
Private Sub CmdExample_Click()

Select Case Me.OptionGrp.Value
Case 1
'do something
Case 2
'do something

End Select

'which option is selected?
MsgBox Me.OptionGrp.Value

End Sub
 
You don't need the command button! You need:

Select Case Me!NameOfOptionGroup
Case 1
<Do this>
Case 2
DoCmd.OpenForm "NameOfYourForm"
Case 3
<Do that>
End Select
 
I prefer a solution that does not need any knowledge of the current option
values.

select case me![grpWhatever]
case me![optThis].optionvalue
case me![optThat].optionvalue
etc.
end select

where optThis, optThat etc. are the controls wihin the option group.

This is safer (IMO) and more "self documenting" than using case 1, case 2,
case 3 etc.

HTH,
TC
 
I think your way is not safer for it will take more code to analyze which
option was selected by interrogating each one of them; assuming that's even
possible.

For self documentation of the case statement, declare a meaningful option
group control name and constants for the values returned.:

Constant SINGLE = 1
Constant MARRIED = 2
etc.
These can be tucked away in a separate module if you like. I put mine in
"modEnum" myself.

Select case MaritalStatus
case SINGLE
case MARRIED
case UNDECIDED
etc.

Yields tight, self documenting code that is not prone to software bugs.

-Jim Shaw


TC said:
I prefer a solution that does not need any knowledge of the current option
values.

select case me![grpWhatever]
case me![optThis].optionvalue
case me![optThat].optionvalue
etc.
end select

where optThis, optThat etc. are the controls wihin the option group.

This is safer (IMO) and more "self documenting" than using case 1, case 2,
case 3 etc.

HTH,
TC


Tony Ford said:
I have an option group on a form, and I want a command
button within the group to perform an action (open
specific form) when the option is selected, and the
command button is clicked. I already know the option
value numbers of each option within the group. How can I
write the expression that will allow me to do this?

Thanks.
 
Huh? The code to "analyze which option was selected" is the 5 lines of code
that I showed in my post. It >is< safer (from a software development
viewpoint) because it >does not< rely on hard-coding the optionvalues of the
option group controls. Read it again!

TC



Jim Shaw said:
I think your way is not safer for it will take more code to analyze which
option was selected by interrogating each one of them; assuming that's even
possible.

For self documentation of the case statement, declare a meaningful option
group control name and constants for the values returned.:

Constant SINGLE = 1
Constant MARRIED = 2
etc.
These can be tucked away in a separate module if you like. I put mine in
"modEnum" myself.

Select case MaritalStatus
case SINGLE
case MARRIED
case UNDECIDED
etc.

Yields tight, self documenting code that is not prone to software bugs.

-Jim Shaw


TC said:
I prefer a solution that does not need any knowledge of the current option
values.

select case me![grpWhatever]
case me![optThis].optionvalue
case me![optThat].optionvalue
etc.
end select

where optThis, optThat etc. are the controls wihin the option group.

This is safer (IMO) and more "self documenting" than using case 1, case 2,
case 3 etc.

HTH,
TC


Tony Ford said:
I have an option group on a form, and I want a command
button within the group to perform an action (open
specific form) when the option is selected, and the
command button is clicked. I already know the option
value numbers of each option within the group. How can I
write the expression that will allow me to do this?

Thanks.
 
Well, not meaning to keep this discussion going, you could code:
obutOne.Value = 1
obutTwo.Value = 2
etc.
hehehe!
CHEERS!
-Jim

TC said:
Huh? The code to "analyze which option was selected" is the 5 lines of code
that I showed in my post. It >is< safer (from a software development
viewpoint) because it >does not< rely on hard-coding the optionvalues of the
option group controls. Read it again!

TC



Jim Shaw said:
I think your way is not safer for it will take more code to analyze which
option was selected by interrogating each one of them; assuming that's even
possible.

For self documentation of the case statement, declare a meaningful option
group control name and constants for the values returned.:

Constant SINGLE = 1
Constant MARRIED = 2
etc.
These can be tucked away in a separate module if you like. I put mine in
"modEnum" myself.

Select case MaritalStatus
case SINGLE
case MARRIED
case UNDECIDED
etc.

Yields tight, self documenting code that is not prone to software bugs.

-Jim Shaw


TC said:
I prefer a solution that does not need any knowledge of the current option
values.

select case me![grpWhatever]
case me![optThis].optionvalue
case me![optThat].optionvalue
etc.
end select

where optThis, optThat etc. are the controls wihin the option group.

This is safer (IMO) and more "self documenting" than using case 1,
case
 
Option group controls do not have a Value attribute!

TC


Jim Shaw said:
Well, not meaning to keep this discussion going, you could code:
obutOne.Value = 1
obutTwo.Value = 2
etc.
hehehe!
CHEERS!
-Jim

TC said:
Huh? The code to "analyze which option was selected" is the 5 lines of code
that I showed in my post. It >is< safer (from a software development
viewpoint) because it >does not< rely on hard-coding the optionvalues of the
option group controls. Read it again!

TC



Jim Shaw said:
I think your way is not safer for it will take more code to analyze which
option was selected by interrogating each one of them; assuming that's even
possible.

For self documentation of the case statement, declare a meaningful option
group control name and constants for the values returned.:

Constant SINGLE = 1
Constant MARRIED = 2
etc.
These can be tucked away in a separate module if you like. I put mine in
"modEnum" myself.

Select case MaritalStatus
case SINGLE
case MARRIED
case UNDECIDED
etc.

Yields tight, self documenting code that is not prone to software bugs.

-Jim Shaw


I prefer a solution that does not need any knowledge of the current option
values.

select case me![grpWhatever]
case me![optThis].optionvalue
case me![optThat].optionvalue
etc.
end select

where optThis, optThat etc. are the controls wihin the option group.

This is safer (IMO) and more "self documenting" than using case 1,
case
2,
case 3 etc.

HTH,
TC


I have an option group on a form, and I want a command
button within the group to perform an action (open
specific form) when the option is selected, and the
command button is clicked. I already know the option
value numbers of each option within the group. How can I
write the expression that will allow me to do this?

Thanks.
 
Sorry for the Typo...Try:

obutOne.OptionValue = 1
etc.
-Jim

TC said:
Option group controls do not have a Value attribute!

TC


Jim Shaw said:
Well, not meaning to keep this discussion going, you could code:
obutOne.Value = 1
obutTwo.Value = 2
etc.
hehehe!
CHEERS!
-Jim

TC said:
Huh? The code to "analyze which option was selected" is the 5 lines of code
that I showed in my post. It >is< safer (from a software development
viewpoint) because it >does not< rely on hard-coding the optionvalues
of
the
option group controls. Read it again!

TC



I think your way is not safer for it will take more code to analyze which
option was selected by interrogating each one of them; assuming that's
even
possible.

For self documentation of the case statement, declare a meaningful option
group control name and constants for the values returned.:

Constant SINGLE = 1
Constant MARRIED = 2
etc.
These can be tucked away in a separate module if you like. I put
mine
in
"modEnum" myself.

Select case MaritalStatus
case SINGLE
case MARRIED
case UNDECIDED
etc.

Yields tight, self documenting code that is not prone to software bugs.

-Jim Shaw


I prefer a solution that does not need any knowledge of the current
option
values.

select case me![grpWhatever]
case me![optThis].optionvalue
case me![optThat].optionvalue
etc.
end select

where optThis, optThat etc. are the controls wihin the option
group.
 
Sorry Jim: that's also wrong!

The >option group< control has a .Value attribute (1, 2, 3 etc.) that varies
at runtime, depending on what option is selected.

The >option< controls (within the group) do not have a .Value attribute.
They have an .OptionValue attribute which is >fixed<, for that particular
option control, at design-time of the form. The OptionValue value >does not
change<, when you select different options in the option group control. So,
if obutOne was assigned OptionValue 1 at design time of the form, the test
that you suggest will >always< succeed, regardless of what option is
actually selected in the option group control, at runtime!

I think you need to go back & study this a bit more carefully :-)

Cheers,
TC


Jim Shaw said:
Sorry for the Typo...Try:

obutOne.OptionValue = 1
etc.
-Jim

TC said:
Option group controls do not have a Value attribute!

TC
optionvalues
of
the
option group controls. Read it again!

TC



I think your way is not safer for it will take more code to analyze
which
option was selected by interrogating each one of them; assuming that's
even
possible.

For self documentation of the case statement, declare a meaningful
option
group control name and constants for the values returned.:

Constant SINGLE = 1
Constant MARRIED = 2
etc.
These can be tucked away in a separate module if you like. I put mine
in
"modEnum" myself.

Select case MaritalStatus
case SINGLE
case MARRIED
case UNDECIDED
etc.

Yields tight, self documenting code that is not prone to software bugs.

-Jim Shaw


I prefer a solution that does not need any knowledge of the current
option
values.

select case me![grpWhatever]
case me![optThis].optionvalue
case me![optThat].optionvalue
etc.
end select

where optThis, optThat etc. are the controls wihin the option
group.
This is safer (IMO) and more "self documenting" than using case 1,
case
2,
case 3 etc.

HTH,
TC


I have an option group on a form, and I want a command
button within the group to perform an action (open
specific form) when the option is selected, and the
command button is clicked. I already know the option
value numbers of each option within the group. How can I
write the expression that will allow me to do this?

Thanks.
 
Well TC, I went back and studied this a bit more; and I'm sticking with my
opinion. Here is what I did.

1. I created a blank database
2. I created an unbound form
3. I Put an option frame on the form called Frame0
4. I defined two option buttons in the frame; Option1 and Option2
5. I took the default button values of 1 and 2 respectively as assigned by
the wizard.
6. In the OnLoad event of the form I coded: Option1.OptionValue = 5
7. In the OnClick event of Frame0 I had a message box display Frame0.value
When I ran the form, guess what happened??!! When I clicked on Option2
button, the value 2 appeared in the message box. When I clicked on Option1,
the value 5 appeared.
Somehow I must have changed a "Fixed" value!!?? Where did I go wrong?

CHEERS & Back to you *g*
-Jim

TC said:
Sorry Jim: that's also wrong!

The >option group< control has a .Value attribute (1, 2, 3 etc.) that varies
at runtime, depending on what option is selected.

The >option< controls (within the group) do not have a .Value attribute.
They have an .OptionValue attribute which is >fixed<, for that particular
option control, at design-time of the form. The OptionValue value >does not
change<, when you select different options in the option group control. So,
if obutOne was assigned OptionValue 1 at design time of the form, the test
that you suggest will >always< succeed, regardless of what option is
actually selected in the option group control, at runtime!

I think you need to go back & study this a bit more carefully :-)

Cheers,
TC


Jim Shaw said:
Sorry for the Typo...Try:

obutOne.OptionValue = 1
etc.
-Jim
lines
of
code
that I showed in my post. It >is< safer (from a software development
viewpoint) because it >does not< rely on hard-coding the
optionvalues
of
the
option group controls. Read it again!

TC



I think your way is not safer for it will take more code to analyze
which
option was selected by interrogating each one of them; assuming that's
even
possible.

For self documentation of the case statement, declare a meaningful
option
group control name and constants for the values returned.:

Constant SINGLE = 1
Constant MARRIED = 2
etc.
These can be tucked away in a separate module if you like. I
put
mine
in
"modEnum" myself.

Select case MaritalStatus
case SINGLE
case MARRIED
case UNDECIDED
etc.

Yields tight, self documenting code that is not prone to software
bugs.

-Jim Shaw


I prefer a solution that does not need any knowledge of the current
option
values.

select case me![grpWhatever]
case me![optThis].optionvalue
case me![optThat].optionvalue
etc.
end select

where optThis, optThat etc. are the controls wihin the option group.


This is safer (IMO) and more "self documenting" than using
case
 
PS: I'm running Access 2002. It that different from your experience?
-Jim

TC said:
Sorry Jim: that's also wrong!

The >option group< control has a .Value attribute (1, 2, 3 etc.) that varies
at runtime, depending on what option is selected.

The >option< controls (within the group) do not have a .Value attribute.
They have an .OptionValue attribute which is >fixed<, for that particular
option control, at design-time of the form. The OptionValue value >does not
change<, when you select different options in the option group control. So,
if obutOne was assigned OptionValue 1 at design time of the form, the test
that you suggest will >always< succeed, regardless of what option is
actually selected in the option group control, at runtime!

I think you need to go back & study this a bit more carefully :-)

Cheers,
TC


Jim Shaw said:
Sorry for the Typo...Try:

obutOne.OptionValue = 1
etc.
-Jim
lines
of
code
that I showed in my post. It >is< safer (from a software development
viewpoint) because it >does not< rely on hard-coding the
optionvalues
of
the
option group controls. Read it again!

TC



I think your way is not safer for it will take more code to analyze
which
option was selected by interrogating each one of them; assuming that's
even
possible.

For self documentation of the case statement, declare a meaningful
option
group control name and constants for the values returned.:

Constant SINGLE = 1
Constant MARRIED = 2
etc.
These can be tucked away in a separate module if you like. I
put
mine
in
"modEnum" myself.

Select case MaritalStatus
case SINGLE
case MARRIED
case UNDECIDED
etc.

Yields tight, self documenting code that is not prone to software
bugs.

-Jim Shaw


I prefer a solution that does not need any knowledge of the current
option
values.

select case me![grpWhatever]
case me![optThis].optionvalue
case me![optThat].optionvalue
etc.
end select

where optThis, optThat etc. are the controls wihin the option group.


This is safer (IMO) and more "self documenting" than using
case
 
Jim, put this in the AfterUpdate event of the option group control:

msgbox (Option1.OptionValue = 1)

You will see that the result is >always< True - or >always< False -
depending 100% on the >design time< selection of the OptionValue property
for option group control, Option1.

The message >does not change< depending on what option is selected in the
option group. It is >always< True, or >always< False, as described above.

Thus a test of that kind is of no use for determining what the current
selection is. The proper way to determine that, is the code that I posted
way back at the start of this thread!

Cheers,
TC


Jim Shaw said:
Well TC, I went back and studied this a bit more; and I'm sticking with my
opinion. Here is what I did.

1. I created a blank database
2. I created an unbound form
3. I Put an option frame on the form called Frame0
4. I defined two option buttons in the frame; Option1 and Option2
5. I took the default button values of 1 and 2 respectively as assigned by
the wizard.
6. In the OnLoad event of the form I coded: Option1.OptionValue = 5
7. In the OnClick event of Frame0 I had a message box display Frame0.value
When I ran the form, guess what happened??!! When I clicked on Option2
button, the value 2 appeared in the message box. When I clicked on Option1,
the value 5 appeared.
Somehow I must have changed a "Fixed" value!!?? Where did I go wrong?

CHEERS & Back to you *g*
-Jim

TC said:
Sorry Jim: that's also wrong!

The >option group< control has a .Value attribute (1, 2, 3 etc.) that varies
at runtime, depending on what option is selected.

The >option< controls (within the group) do not have a .Value attribute.
They have an .OptionValue attribute which is >fixed<, for that particular
option control, at design-time of the form. The OptionValue value >does not
change<, when you select different options in the option group control. So,
if obutOne was assigned OptionValue 1 at design time of the form, the test
that you suggest will >always< succeed, regardless of what option is
actually selected in the option group control, at runtime!

I think you need to go back & study this a bit more carefully :-)

Cheers,
TC


Jim Shaw said:
Sorry for the Typo...Try:

obutOne.OptionValue = 1
etc.
-Jim

Option group controls do not have a Value attribute!

TC


Well, not meaning to keep this discussion going, you could code:
obutOne.Value = 1
obutTwo.Value = 2
etc.
hehehe!
CHEERS!
-Jim

Huh? The code to "analyze which option was selected" is the 5
lines
of
code
that I showed in my post. It >is< safer (from a software development
viewpoint) because it >does not< rely on hard-coding the optionvalues
of
the
option group controls. Read it again!

TC



I think your way is not safer for it will take more code to analyze
which
option was selected by interrogating each one of them; assuming
that's
even
possible.

For self documentation of the case statement, declare a meaningful
option
group control name and constants for the values returned.:

Constant SINGLE = 1
Constant MARRIED = 2
etc.
These can be tucked away in a separate module if you like. I put
mine
in
"modEnum" myself.

Select case MaritalStatus
case SINGLE
case MARRIED
case UNDECIDED
etc.

Yields tight, self documenting code that is not prone to software
bugs.

-Jim Shaw


I prefer a solution that does not need any knowledge of the
current
option
values.

select case me![grpWhatever]
case me![optThis].optionvalue
case me![optThat].optionvalue
etc.
end select

where optThis, optThat etc. are the controls wihin the option
group.


This is safer (IMO) and more "self documenting" than using
case
1,
case
2,
case 3 etc.

HTH,
TC


I have an option group on a form, and I want a command
button within the group to perform an action (open
specific form) when the option is selected, and the
command button is clicked. I already know the option
value numbers of each option within the group. How can I
write the expression that will allow me to do this?

Thanks.
 
TC;
We must be using different versions of Access. I'm using Microsoft's
Access/XP (2002). I have all service packs and upgrades installed also.
Which version are you using?

I did as you suggested-- the results prove my point, not yours.

With a design time specification of 1 for the option value and a run time
setting of the value to 5,
the test (Option1.OptionValue = 1) >always< returns false and
(Option1.OptionValue =5) returns true. I also got the same result testing
the frame's value. My logic works as I stated.

What say you now??

Seasons Greetings
Jim


TC said:
Jim, put this in the AfterUpdate event of the option group control:

msgbox (Option1.OptionValue = 1)

You will see that the result is >always< True - or >always< False -
depending 100% on the >design time< selection of the OptionValue property
for option group control, Option1.

The message >does not change< depending on what option is selected in the
option group. It is >always< True, or >always< False, as described above.

Thus a test of that kind is of no use for determining what the current
selection is. The proper way to determine that, is the code that I posted
way back at the start of this thread!

Cheers,
TC


Jim Shaw said:
Well TC, I went back and studied this a bit more; and I'm sticking with my
opinion. Here is what I did.

1. I created a blank database
2. I created an unbound form
3. I Put an option frame on the form called Frame0
4. I defined two option buttons in the frame; Option1 and Option2
5. I took the default button values of 1 and 2 respectively as assigned by
the wizard.
6. In the OnLoad event of the form I coded: Option1.OptionValue = 5
7. In the OnClick event of Frame0 I had a message box display Frame0.value
When I ran the form, guess what happened??!! When I clicked on Option2
button, the value 2 appeared in the message box. When I clicked on Option1,
the value 5 appeared.
Somehow I must have changed a "Fixed" value!!?? Where did I go wrong?

CHEERS & Back to you *g*
-Jim

TC said:
Sorry Jim: that's also wrong!

The >option group< control has a .Value attribute (1, 2, 3 etc.) that varies
at runtime, depending on what option is selected.

The >option< controls (within the group) do not have a .Value attribute.
They have an .OptionValue attribute which is >fixed<, for that particular
option control, at design-time of the form. The OptionValue value
does
not
change<, when you select different options in the option group
control.
So,
if obutOne was assigned OptionValue 1 at design time of the form, the test
that you suggest will >always< succeed, regardless of what option is
actually selected in the option group control, at runtime!

I think you need to go back & study this a bit more carefully :-)

Cheers,
TC


Sorry for the Typo...Try:

obutOne.OptionValue = 1
etc.
-Jim

Option group controls do not have a Value attribute!

TC


Well, not meaning to keep this discussion going, you could code:
obutOne.Value = 1
obutTwo.Value = 2
etc.
hehehe!
CHEERS!
-Jim

Huh? The code to "analyze which option was selected" is the 5 lines
of
code
that I showed in my post. It >is< safer (from a software development
viewpoint) because it >does not< rely on hard-coding the
optionvalues
of
the
option group controls. Read it again!

TC



I think your way is not safer for it will take more code to
analyze
which
option was selected by interrogating each one of them; assuming
that's
even
possible.

For self documentation of the case statement, declare a meaningful
option
group control name and constants for the values returned.:

Constant SINGLE = 1
Constant MARRIED = 2
etc.
These can be tucked away in a separate module if you like.
I
put
mine
in
"modEnum" myself.

Select case MaritalStatus
case SINGLE
case MARRIED
case UNDECIDED
etc.

Yields tight, self documenting code that is not prone to software
bugs.

-Jim Shaw


I prefer a solution that does not need any knowledge of the
current
option
values.

select case me![grpWhatever]
case me![optThis].optionvalue
case me![optThat].optionvalue
etc.
end select

where optThis, optThat etc. are the controls wihin the option
group.


This is safer (IMO) and more "self documenting" than using case
1,
case
2,
case 3 etc.

HTH,
TC


message
I have an option group on a form, and I want a command
button within the group to perform an action (open
specific form) when the option is selected, and the
command button is clicked. I already know the option
value numbers of each option within the group. How can I
write the expression that will allow me to do this?

Thanks.
 
Hi Jim

I use A97, but I'm sure it works the same in all versions.

Perhaps we are talking at cross-purposes due to an excess of xmas libations?
:-)

All that I am saying, is this. A test like the following will never serve to
determine what option is currently selected in an option group control:

If me![option_control_name] = any_constant then ...

(option_control_name is the name of one control within the group - not the
name of the group control itself.)

This is because a test of that kind will >always< be true, or >always< be
false, depending on design-time selections. It will never produce different
results depending on what option is selected at runtime. If you disagree
with that, you'll need to show me some actual code to support your
contention!

Cheers!
TC


Jim Shaw said:
TC;
We must be using different versions of Access. I'm using Microsoft's
Access/XP (2002). I have all service packs and upgrades installed also.
Which version are you using?

I did as you suggested-- the results prove my point, not yours.

With a design time specification of 1 for the option value and a run time
setting of the value to 5,
the test (Option1.OptionValue = 1) >always< returns false and
(Option1.OptionValue =5) returns true. I also got the same result testing
the frame's value. My logic works as I stated.

What say you now??

Seasons Greetings
Jim


TC said:
Jim, put this in the AfterUpdate event of the option group control:

msgbox (Option1.OptionValue = 1)

You will see that the result is >always< True - or >always< False -
depending 100% on the >design time< selection of the OptionValue property
for option group control, Option1.

The message >does not change< depending on what option is selected in the
option group. It is >always< True, or >always< False, as described above.

Thus a test of that kind is of no use for determining what the current
selection is. The proper way to determine that, is the code that I posted
way back at the start of this thread!

Cheers,
TC
with
assigned
by
the wizard.
6. In the OnLoad event of the form I coded: Option1.OptionValue = 5
7. In the OnClick event of Frame0 I had a message box display Frame0.value
When I ran the form, guess what happened??!! When I clicked on Option2
button, the value 2 appeared in the message box. When I clicked on Option1,
the value 5 appeared.
Somehow I must have changed a "Fixed" value!!?? Where did I go wrong?

CHEERS & Back to you *g*
-Jim

Sorry Jim: that's also wrong!

The >option group< control has a .Value attribute (1, 2, 3 etc.) that
varies
at runtime, depending on what option is selected.

The >option< controls (within the group) do not have a .Value attribute.
They have an .OptionValue attribute which is >fixed<, for that particular
option control, at design-time of the form. The OptionValue value does
not
change<, when you select different options in the option group control.
So,
if obutOne was assigned OptionValue 1 at design time of the form,
the
test
that you suggest will >always< succeed, regardless of what option is
actually selected in the option group control, at runtime!

I think you need to go back & study this a bit more carefully :-)

Cheers,
TC


Sorry for the Typo...Try:

obutOne.OptionValue = 1
etc.
-Jim

Option group controls do not have a Value attribute!

TC


Well, not meaning to keep this discussion going, you could code:
obutOne.Value = 1
obutTwo.Value = 2
etc.
hehehe!
CHEERS!
-Jim

Huh? The code to "analyze which option was selected" is the 5
lines
of
code
that I showed in my post. It >is< safer (from a software
development
viewpoint) because it >does not< rely on hard-coding the
optionvalues
of
the
option group controls. Read it again!

TC



I think your way is not safer for it will take more code to
analyze
which
option was selected by interrogating each one of them; assuming
that's
even
possible.

For self documentation of the case statement, declare a
meaningful
option
group control name and constants for the values returned.:

Constant SINGLE = 1
Constant MARRIED = 2
etc.
These can be tucked away in a separate module if you like. I
put
mine
in
"modEnum" myself.

Select case MaritalStatus
case SINGLE
case MARRIED
case UNDECIDED
etc.

Yields tight, self documenting code that is not prone to
software
bugs.

-Jim Shaw


I prefer a solution that does not need any knowledge of the
current
option
values.

select case me![grpWhatever]
case me![optThis].optionvalue
case me![optThat].optionvalue
etc.
end select

where optThis, optThat etc. are the controls wihin the option
group.


This is safer (IMO) and more "self documenting" than using
case
1,
case
2,
case 3 etc.

HTH,
TC


message
I have an option group on a form, and I want a command
button within the group to perform an action (open
specific form) when the option is selected, and the
command button is clicked. I already know the option
value numbers of each option within the group. How
can
 
TC
Now we are getting somewhere!
If you go back over my messages, I've used the following names to mean:
"OptionButton" => the control used to specify which option is selected
"Frame" => the group control that contains the set of OptionButtons.

Now, I agree that testing the value of OptionButton to see if that option
has been selected won't work. For that function, one must test the value of
the Frame Control, for that is the control whose value changes when an
OptionButton changes state. In earlier days, these were called "Radio
Buttons". You could only push one radio button at a time, and if pressed,
any other button pushed would pop out. The radio (Frame) would switch to
the station (Frame.Value) selected.

Additionally, OptionButton.OptionValue contains the value (radio station)
assigned to that button. When delivered (designed), each option button was
set to a specific station (value), BUT the new owner (application) had the
option to change the station (value) assigned to each button, as often as
he/she liked, whenever they liked, even while traveling down the highway
(dynamically).

One could listen to the radio station (test the value of the option group
control (Frame)) to determine which radio button had been pushed.

I believe we are now in agreement, and probably always have been. Such is
the ambiguity if the English language. If we in fact, are not in agreement,
I have a tiny demo database that demonstrates my position. Would love to
send it to you, but I don't know how big a file the newsgroup will accept.
However, the code module for my form follows. The control group is Frame0.
The controls are Option2 and Option3.
Design time values are Option2 = 1, Option3=2.
-----------------cut line--------------------------
Option Compare Database

Private Sub Form_Open(Cancel As Integer)
Option3.OptionValue = 5

End Sub

Private Sub Frame0_AfterUpdate()
MsgBox "Option3 test for 5 returns " & (Option3.OptionValue = 5)
'Returns TRUE
MsgBox "Frame0 test for five returns " & (Frame0.Value = 5)
'Returns TRUE

End Sub

Private Sub Frame0_Click()
MsgBox "Value is " & Frame0.Value 'Returns either 1 or 5
End Sub
-----------------cut line--------------------------
If running this code on A97 works differently, I submit that the two Access
versions behave differently. This leads to a discussion of which coding
method best preserves the business logic of the application across the
various existing (and future) Microsoft product migrations. Failure to
manage these selections correctly, leads one into either a career of program
maintenance over one of new development, or, a continual need to update
one's resume. We used to talk about paying programmers a royalty on
application programs that ran without the need for maintenance. Wouldn't
that be fun?

-Jim


TC said:
Hi Jim

I use A97, but I'm sure it works the same in all versions.

Perhaps we are talking at cross-purposes due to an excess of xmas libations?
:-)

All that I am saying, is this. A test like the following will never serve to
determine what option is currently selected in an option group control:

If me![option_control_name] = any_constant then ...

(option_control_name is the name of one control within the group - not the
name of the group control itself.)

This is because a test of that kind will >always< be true, or >always< be
false, depending on design-time selections. It will never produce different
results depending on what option is selected at runtime. If you disagree
with that, you'll need to show me some actual code to support your
contention!

Cheers!
TC


Jim Shaw said:
TC;
We must be using different versions of Access. I'm using Microsoft's
Access/XP (2002). I have all service packs and upgrades installed also.
Which version are you using?

I did as you suggested-- the results prove my point, not yours.

With a design time specification of 1 for the option value and a run time
setting of the value to 5,
the test (Option1.OptionValue = 1) >always< returns false and
(Option1.OptionValue =5) returns true. I also got the same result testing
the frame's value. My logic works as I stated.

What say you now??

Seasons Greetings
Jim


with assigned
the
5
lines
of
code
that I showed in my post. It >is< safer (from a software
development
viewpoint) because it >does not< rely on hard-coding the
optionvalues
of
the
option group controls. Read it again!

TC



I think your way is not safer for it will take more code to
analyze
which
option was selected by interrogating each one of them;
assuming
that's
even
possible.

For self documentation of the case statement, declare a
meaningful
option
group control name and constants for the values returned.:

Constant SINGLE = 1
Constant MARRIED = 2
etc.
These can be tucked away in a separate module if you
like.
I
put
mine
in
"modEnum" myself.

Select case MaritalStatus
case SINGLE
case MARRIED
case UNDECIDED
etc.

Yields tight, self documenting code that is not prone to
software
bugs.

-Jim Shaw


I prefer a solution that does not need any knowledge
of
the
current
option
values.

select case me![grpWhatever]
case me![optThis].optionvalue
case me![optThat].optionvalue
etc.
end select

where optThis, optThat etc. are the controls wihin the
option
group.


This is safer (IMO) and more "self documenting" than using
case
1,
case
2,
case 3 etc.

HTH,
TC


 
Back
Top