Change field from text box to combo box on different form

  • Thread starter Thread starter Pamela
  • Start date Start date
P

Pamela

I have field Inspection_Location in my table which I originally set up to be
text. This field needs to be used on 2 different forms - 1 form needs the
data displayed as an option box with 3 or 4 options and the other form needs
the data displayed as text. How can I do this?
 
These are not mutually exclusive actions. On one form you would insert a
textbox to display the data as text. On the other form you would choose to
insert an option group. The wizard walks you through the steps. However, the
trick is having the option group store the values as text as opposed to a
number. Option groups, by default, store the number associated with your
selection. Thus, when you look at the form with the text, it would merely
show a number.

You will need code in two places in order to have the option group store the
data as text instead of numbers.

First, on form you have the option group place a textbox for the filed on
the form and select "No" for Visible under Format on the Property Sheet. This
will have the field available for the code, but won't show it on your form.
You can place this control anywhere on the form.

Next, in the On Current event you will need code something like this:

--------------------------------------------------------------------------------------
'Syncs the Option Group with the Textbox

Select Case Me.NameOfControl

Case Is = "Value1"
Me.NameOfFrameForOptionGroup = 1
Case Is = "Value2"
Me.NameOfFrameForOptionGroup = 2
Case Is = "Value3"
Me.NameOfFrameForOptionGroup = 3

Case Else
Me.NameOfFrameForOptionGroup = Null

End Select

-------------------------------------------------------------------------------------------

This assumes that you have three choices. If you have four options you would
add:

Case Is = "Value4"
Me.NameOfFrameForOptionGroup = 4

You would replace NameOfControl with the name of the textbox and
NameOfFrameForOptionGroup with the name of the frame for the option group.
This is important as the frame holds the data in an option group, not the
options themselves. You would replace Value1 through Value4 with the text you
would like to show for each selection to replace the numbers assigned during
the wizard. Make sure you match them up with what was done in the wizard.

The second code will be done on the frame of the option group. On the Before
Update event put the following code:
 
Back
Top