Hiding text box based on previous combo box data entry

HKJ

New member
Local time
Today, 15:18
Joined
Jul 26, 2010
Messages
7
Ok. I've been wrestling with what seems like very simple VBA code and I'm still having problems with hiding controls in my form.
In my Form, I have a combo box "Diagnosis" with several row source selections (value list). One of the selections is "Other".
When "Other" is selected or checked, I want the next text box (called "Other Diagnosis") on the form to become visible.
I do not want the "Other Detail" text box visible on my form, unless "Other" is checked in the preceding combo box labeled "Diagnosis".
This is the code I've been using with no success: Thanks for your help.

Private Sub Diagnosis_AfterUpdate()
If Me.Diagnosis_combobox = "Other" Then
Me.[Other_Diagnosis].Visible = True
Else
Me.[Other_Diagnosis].Visible = False
End If
End Sub

Private Sub Diagnosis_comboboxcurrent()
If Me.Diagnosis_combobox = "Other" Then
Me.[Other_Diagnosis].Visible = True
Else
Me.[Other_Diagnosis].Visible = False
End If
End Sub
 
Private Sub Diagnosis_AfterUpdate()
If Me.Diagnosis_combobox = "Other" Then
Me.[Other_Diagnosis].Visible = True
Else
Me.[Other_Diagnosis].Visible = False
End If
End Sub

Private Sub Diagnosis_comboboxcurrent()
If Me.Diagnosis_combobox = "Other" Then
Me.[Other_Diagnosis].Visible = True
Else
Me.[Other_Diagnosis].Visible = False
End If
End Sub

In your first example you have Diagnosis as the name of your combo box then in the IF statement you have Diagnosis_combobox.

In your second example you have Diagnosis_comboboxcurrent() which should be Diagnosis_combobox_current()

Try this in the After Update
Private Sub Diagnosis_combobox_AfterUpdate()
If Me!Diagnosis_combobox= "Other" Then
Me![other diagnosis].Visible = True
Else
Me![other diagnosis].Visible = False
End If
End Sub
 
Thanks Poppa Smurf. However, when I enter your code in the After Update,
it returns the error:
"End If without block if"
 
Then you have an extra end if in your code.
 
But I don't have an extra "end if" in my code.
Here's what I have: (The below bolded code happens to also be highlighted in the code debugger).

Private Sub Diagnosis_combobox_AfterUpdate()
If Me!Diagnosis_combobox = "Other" Then Me![Other_Diagnosis].Visible = True Else Me![Other_Diagnosis].Visible = False
End If
End Sub
 
Yes you actually do. Look at it again and look at Poppa Smurf's code.
 
One line IFs ;) See why some of us don't use them (often) :D
 
Here is a tip that I learnt a long time ago using 3rd generation languages. When using IFs the next line must be END IF then enter your code before the END IF, this also applies to other structures like Loops Select Cases etc.
 
But I don't have an extra "end if" in my code.
Here's what I have: (The below bolded code happens to also be highlighted in the code debugger).

Private Sub Diagnosis_combobox_AfterUpdate()
If Me!Diagnosis_combobox = "Other" Then Me![Other_Diagnosis].Visible = True Else Me![Other_Diagnosis].Visible = False
End If
End Sub

This is how your code should look...

Code:
If Me.Diagnosis_combobox = "Other" Then
     Me.[Other_Diagnosis].Visible = True
Else
     Me.[Other_Diagnosis].Visible = False
End If
 

Users who are viewing this thread

Back
Top Bottom