visible/invisible based on combo box selection

joe789

Registered User.
Local time
Today, 12:49
Joined
Mar 22, 2001
Messages
154
Hi Folks,

I have a combo box that accepts a single value from a list of items (no free entry allowed). One of the items a user can select is 'Other'. If a user selects the 'Other' item from the aforementioned combo box, it is expected that the user populates what 'Other' is in a text field next to the combo box designated for that purpose. My question is how would I be able to hide the 'Specify Other' text box unless the user select 'Other' from the combo box and visa-versa?

Thank you much for any help,

Joe
 
In your onload event for the form, set the txtbox property for visible to false.

Then in the afterupdate event for the combo box, create an if-then statement that declares if the combo box value is equal to "Other", then the property for visible for the hidden txt box is set to True.

Alan
 
Alan, You need to use the current event rather than the load event. The load event only runs once when the form is loaded so it will work only if the form has no ability to scroll to a different record and no search feature. The current event runs once for each record.

So the code goes in the Form's Current event and in the control's AfterUpdate event. If this is the only code in the Current event, then just call it from the AfterUpdate event rather than repeating it. Or create a separate sub in the Form's class module and call it from both places.

Code:
If Me.YourCombo = "Other" Then
    Me.OtherText.Visible = True
Else
    Me.OtherText.Visible = False
End If
 
Thanks Pat,
Short memory does that to me. Glad that you are here to cover my back.:)

Alan
 
Folks,

Thank you for the quick reply. I have tried the code found below with different 'key words' to find that nothing seems to be working. The code produces an error or does not render and error but does nothing. Any help would be appreciated:

If Me.Combo188.[*KEYWORD] = "Other" Then
Me.Label191.Visible = True And Me.Text190.Visible = True
Else
Me.Label191.Visible = False And Me.Text190.Visible = False
End If

*[KEYWORD] list tried:
InSelection
ItemData
ItemsSelected
ListIndex
Selected
TabIndex
Text
Value
 
Take out the [KEYWORD] from the code. It is not needed. Look at the code that Pat gave you.

BTW: I would use more descriptive names for my controls. Later on when you are trying to decipher what you did a year ago, your generic names will haunt you.

Alan
 
If the combo's bound field is numeric and the text is just for display, you have two choices.
1. compare to the numeric value - If Me.combo188 = 12
or
2. reference the text column which is probably column 2 - If Me.combo.column(1) = "Other"

The combo and list boxes are zero based arrays so .column(0) is the first column and .column(1) is the second column.

It is best to name your controls with meaningful names BEFORE you start writing code. Are you going to remember next week, let alone next year what label191 is?
 
fyi - And this method will not work if you happen to be using a 'continuous form'. :)
 
Alan, You need to use the current event rather than the load event. The load event only runs once when the form is loaded so it will work only if the form has no ability to scroll to a different record and no search feature. The current event runs once for each record.

So the code goes in the Form's Current event and in the control's AfterUpdate event. If this is the only code in the Current event, then just call it from the AfterUpdate event rather than repeating it. Or create a separate sub in the Form's class module and call it from both places.

Code:
If Me.YourCombo = "Other" Then
    Me.OtherText.Visible = True
Else
    Me.OtherText.Visible = False
End If

Hi all,

I am trying to accomplish the same thing as the OP. I have tried using this code and following the suggestions of the other posters but can't get it to work right. Here is the code I used:

Code:
Private Sub Form_Current()
If Me.TypeOfBusiness = "Industry" Then
    Me.IndustryClassification.Visible = True
Else
    Me.IndustryClassification.Visible = False
End If
End Sub
Private Sub TypeOfBusiness_AfterUpdate()
If Me.TypeOfBusiness = "Industry" Then
    Me.IndustryClassification.Visible = True
Else
    Me.IndustryClassification.Visible = False
End If
End Sub

When I open the form and try to use the control, I receive the following error: "Run-time error '13': Type mismatch" and it takes me to the code with this line highlighted: If Me.TypeOfBusiness = "Industry" Then

Anyone know how I can fix this?

Thanks much.
 
Is Me.TypeOfBusiness a combo? See my post #7

You should also consider using conditional formatting since as Ken has pointed out, this method won't work on forms in datasheet or continuous view.
 

Users who are viewing this thread

Back
Top Bottom