Making the Visibility of a Text Box Dependent on Combo Box Selection

wilderfan

Registered User.
Local time
Yesterday, 23:21
Joined
Mar 3, 2008
Messages
172
This is my first post.

In one of my Forms, I have a combo box which allows users to describe a new record from a list of 5 possible options.

If users choose one particular description from the 5 options, then I would like the form to display a previously hidden text box and label.

I want the text box and label to be hidden on the form, except when users choose that one particular option in the combo box.

I think I'm going to need to insert some VBA code for this Form, but I'm not very familiar with VBA.

Any suggestions?
 
In the after update event of the combo:

Code:
If Me.ComboName = "Whatever" Then
  Me.TextBox.Visible = True
Else
  Me.TextBox.Visible = False
End If
 
Thanks, Paul.

For the Text Box Properties, I have currently set Visible = No.

Should I change that setting?
 
No, that will make it invisible to start with, which sounds like what you want. The code should make it visible as appropriate based on the combo selection.
 
It works, Paul.

But I think I may need to "tweak" the coding a little.

When I scroll through the records by clicking on the right-pointing arrow at the bottom of the Form, the Text Box remains invisible even when I scroll onto a record that contains the combo box setting that is supposed to trigger the appearance of the Text Box.

The Text Box DOES appear when I click on the combo box setting that is supposed to make it visible.

Once visible, the Text Box remains on the Form even when I continue scrolling through records which do not have the combo box set to the "trigger" description.

Is there any way to address the visibility of the Text Box while scrolling through the numerous records?
 
Add the same code to the current event of the form, which fires when records are changed.
 
And the data from the combobox will have to be bound to some field in your table, of course, in order for the visibility to be correct for each record.
 
Many thanks, Paul.

It worked exactly as you said it would.
 
I would like to try just the same. But it won't work.
The steps I followed.
I made a table 'tools'
I made a table with the 'kind of tools'
I made a combobox in the form of the table tools with the source 'kind of tools'
I made a form from the table tools
Now I would like to make a text box visible depending of the choice in the combobox.
Do I have to put relationchips between the table 'kind of tools' and the table 'tools' before it works?
And what does the Me means?
My code:
Private Sub Soort_Meettoestel_afterUpdate(Cancel As Integer)
If Me.Soort_Meettoestel = "Schuifmaat" Then
Me.LVOET.Visible = True
Else: Me.LVOET.Visible = False
End If

LVOET is the name of the Textbox
 
"Me" is a shortcut way to refer to the object containing the code, in this case the form. Make sure your combo doesn't have 2 columns and you're referring to the wrong one. I'm not personally a fan of mixing the block and 1-line formats of the If/Then.
 

Users who are viewing this thread

Back
Top Bottom