Option Buttons

J

jay_2882

Hi,

I'm trying to use option buttons on a form to output a value other than 1,
2, or 3 to my table. It needs to output a character instead, E, TD or C.
However, I can only get the numbers to output. Any help would be appreciated.
Thanks,
-jay_2882
 
R

Rob Parker

An option group, and its option buttons, can only generate integers. If you
want to use it to set text values in your data, you can do this in one of
two ways:

1. Use code in the AfterUpdate event of the optiongroup to convert its
output to the string you want. For example:
Private Sub MyOptionGroup_AfterUpdate()
Select Case MyOptionGroup
Case 1
Me!MyBoundField = "E"
Case 2
Me!MyBoundField = "TD"
Case 3
Me!MyBoundField = "C"
Case Else
Me!MyBoundField = Null
End Select
End Sub

This assumes that the option group is unbound, and that you want to save its
(converted) value to an underlying field MyBoundField in the form's
recordset.

2. Have the option group bound to the underlying field in your form's
recordset, which will need to be an integer number datatype. This will
store the value (1,2,3) from the optiongroup directly to your table. Set up
a lookup table with two fields to convert the number to a text value, and
join this table to the original table in a query to display the text value
corresponding to the integer. Base forms/reports on the query, rather than
the table.

HTH,

Rob
 
K

Klatuu

Thi s would be a good place to use the Choose function. In the Option
Group's After Update event, assign the value to a variable or another control:

=Choose(Me.opgFoo, "E","TD","C")
 
Top