Getting text output from Option Button?

G

Guest

Forgive me, I'm new to Access,

I'm after getting a text output from a option button in a group rather than
a number,

I have three option buttons called "Option1", "Option2" and "Option3" within
an Option Group frame called "Frame1". The Frame is linked to table called
"Master" and the control source is named "High".

I searched previous posting and got the code as follows, that is within a
module called "Module1".

Private Sub Frame1_AfterUpdate()

Select Case Frame1

Case 1
Me.High = "High"

Case 2
Me.High = "Low"

Case 3
Me.High = "N/A"

End Select
End Sub


This transfers the text when an option button is selected, but the option
button does not go black but grayed out instead, the problem I have is when I
move to another field on the form, all three checkboxes grey out.

How can I alter the code so that the option button goes black and stays that
way when tabbing to the next field?

Hope that makes sense!
 
F

fredg

Forgive me, I'm new to Access,

I'm after getting a text output from a option button in a group rather than
a number,

I have three option buttons called "Option1", "Option2" and "Option3" within
an Option Group frame called "Frame1". The Frame is linked to table called
"Master" and the control source is named "High".

I searched previous posting and got the code as follows, that is within a
module called "Module1".

Private Sub Frame1_AfterUpdate()

Select Case Frame1

Case 1
Me.High = "High"

Case 2
Me.High = "Low"

Case 3
Me.High = "N/A"

End Select
End Sub

This transfers the text when an option button is selected, but the option
button does not go black but grayed out instead, the problem I have is when I
move to another field on the form, all three checkboxes grey out.

How can I alter the code so that the option button goes black and stays that
way when tabbing to the next field?

Hope that makes sense!

That's not how to get a text value from an Option Group.
The Option Group must be bound to a Number - Integer datatype field in
the table.
The table field will store the selected option value, 1, 2, 3, etc.

There are several ways to convert this number value to text.

In a query:
ShowText:Choose([OptionName],"High","Low","N/A")

You can use the same Choose() expression directly in a report or on a
form.

As an alternative method you can use Select Case in VBA
Dim strMyText as String
Select Case [OptionName]
Case is = 1
strMyText = "High"
Case is = 2
strMyText = "Low"
etc.
End Select

Or you can use IIF directly in the control source of an unbound
control:

=IIf([OptionName] = 1,"High",IIf([OptionName] = 2,"Low","N/A"))
 
G

Guest

Thankyou, went for option one, just what I wanted.
--
This post was created using recycled electrons!


fredg said:
Forgive me, I'm new to Access,

I'm after getting a text output from a option button in a group rather than
a number,

I have three option buttons called "Option1", "Option2" and "Option3" within
an Option Group frame called "Frame1". The Frame is linked to table called
"Master" and the control source is named "High".

I searched previous posting and got the code as follows, that is within a
module called "Module1".

Private Sub Frame1_AfterUpdate()

Select Case Frame1

Case 1
Me.High = "High"

Case 2
Me.High = "Low"

Case 3
Me.High = "N/A"

End Select
End Sub

This transfers the text when an option button is selected, but the option
button does not go black but grayed out instead, the problem I have is when I
move to another field on the form, all three checkboxes grey out.

How can I alter the code so that the option button goes black and stays that
way when tabbing to the next field?

Hope that makes sense!

That's not how to get a text value from an Option Group.
The Option Group must be bound to a Number - Integer datatype field in
the table.
The table field will store the selected option value, 1, 2, 3, etc.

There are several ways to convert this number value to text.

In a query:
ShowText:Choose([OptionName],"High","Low","N/A")

You can use the same Choose() expression directly in a report or on a
form.

As an alternative method you can use Select Case in VBA
Dim strMyText as String
Select Case [OptionName]
Case is = 1
strMyText = "High"
Case is = 2
strMyText = "Low"
etc.
End Select

Or you can use IIF directly in the control source of an unbound
control:

=IIf([OptionName] = 1,"High",IIf([OptionName] = 2,"Low","N/A"))
 
J

John Spencer

Of course, there is always the option of adding a table that contains two
fields. Field one is the option number and field two is the text
equivalent. Then all you need to do is link to the table in queries where
you need to display the text value.

Field: OptionValue (1,2,3, etc)
Field: TextValue ("High","Low","N/A")

If you have a multiple option groups, you can use different ranges in the
same table for the option groups (or you can use multiple tables). If you
decide to use one table for many option groups, you will need to set the
values for the each option group item appropriately.

I personnally like the table approach since it allows me flexability in
setting the text values. One problem with it is that the labels on the
options can get out of synch with the text values in the table if you change
the table's text values. That can be handled with code that sets the
caption of the labels if needed. A benefit is that I can have an
abbreviated label on a form and a fully expanded text value for use in a
report.

Just my two cents.

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 

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