.Visible not working?

mattstrachan

Registered User.
Local time
Today, 12:39
Joined
Feb 22, 2013
Messages
31
Hello all,

I have a form that has comboboxes with an "Other" option. I want to make a textbox that appears when "Other" is selected and then the user can input information. I have five combo boxes that I would like to do this on.

I have put this code in the Form_Current and cbo_Change event procedures:

Private Sub cboShape_Change()

If Forms!Product!cboShape = "Other" Then
Forms!Product!txtShapeAdditional.Visible = True
Else
Forms!Product!txtShapeAdditional = " "
Forms!Product!txtShapeAdditional.Visible = False
End If

End Sub


This works great and I have used this code with four of my combo boxes. Now I am on to the fifth combo box and the code will not work at all! Here is the exact code that does not work.

Private Sub cboSpecies_Change()

If Forms!Product!cboSpecies = "Multiple Species" Then
Forms!Product!txtSpeciesAdditional.Visible = True
Else
Forms!Product!txtSpeciesAdditional = " "
Forms!Product!txtSpeciesAdditional.Visible = False
End If

End Sub

Any help determining why this suddenly does not work?

Could I have a property set incorrectly? This does not seem possible because I copy/pasted the txtSpeciesAdditional from the txtShapeAdditional but perhaps.
 
1. Use the After Update event of the combo box not the Change event.

2. put a message box into the code to return the value of the cboSpecies so you can see if it is returning what you think it should be returning.
 
Are your combo boxes all on the same form? If so, then you can reference them by using Me. instead of Forms!Product!cboShape:

So Me.cboShape

Also, you can use the Case Select statement for your combo box if the value are constant;

Code:
Private Sub cboSpecies_AfterUpdate()
   Select Case Me.cboSpecies
    Case "Multiple Species"
        Me.txtSpeciesAdditional.Visible = True
    Case "Other"
        Me.txtSpeciesAdditional = ""
        Me.txtSpeciesAdditional.Visible = False
    Case Else
    End Select
End Sub

By the way, your code above works for me in the AfterUpdate event of the combo box
 
Last edited:
Well the messagebox idea solved the problem. It was returning the SpeciesID instead of the actual Species name. So thank you for that.
 

Users who are viewing this thread

Back
Top Bottom