Show (visible) Text box/field determined by combo box selection

D

Dagny Taggart

I have a form that I want to keep a field hidden until a certain selection is
chosen within a drop-down combo box. I know this can be down via visual
basics, but don't know where to start. I am familiar with vb, but I don't
what event to call...a push in the right direction would be appreciated.

Thanks-in-advance
 
J

Jeff Boyce

Dagny

In the combo box's AfterUpdate event, you could add code that checks for
which selection was made, then handles the other control ... something like:

If Me.cboThisComboBox = XXXXX Then
Me.txtTheHiddenTextBox.Visible = True
Else
Me.txtTheHiddenTextBox.Visible = True
End If

A more "elegant" way might be something like:

Me.txtTheHiddenTextBox.Visible = (Me.cboThisComboBox = XXXXX )

You'd need to substitute the names of your controls, and the value you are
testing for (not XXXXX, right?!).

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
J

jmonty

Open the form in design mode. Right click on the textbox and select properties.
Set the Visible property to No. Close the properties and Save. Next
right-click on the the ComboBox this time and Select Build Event, then Code
Builder. I believe it will create the subroutine for the BeforeUpdate event
for you. Now with the Code module open, select the Click event from the drop
down at the top right. It will create the code for the Click event for you.
Now for this example - Mine is named Combo0, your's might be named different
- that's ok. (same for the text box names). Next use the VBA code to change
the visible property based on the value of the combobox:

Private Sub Combo0_Click()
If Me.Combo0 = "Desired Value" then
Me.Text1.Visible = True
Else
Me.Text1.Visible = False
End If
End Sub

Save and close.

jmonty
 
D

Dagny Taggart

Thanks Jeff and Jmonty for your help.

But I need to ask for a little bit more assistance. I need to know how to
have the field show up when scrolling through. So if that category has been
chosen and it is in the table, what would be the event to show the field when
it is true in the table. I hope this makes sense.

Thanks-in-advance
 
J

Jeff Boyce

Dagny

What is "scrolling through"?

Do you mean you want the invisible field to show if the correct item is
displayed in the combo box? Even if it hasn't been "selected"?

When your form loads a record (e.g., the OnCurrent event), you could call
the procedure that runs after a selection is made in the combo box...
something like:

Call cboYourComboBox_AfterUpdate()

This would trigger the same test/check/code that runs in, well, the
AfterUpdate event.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
Top