Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

COMBO BOX

Status
Not open for further replies.

ksimmsa

Programmer
Feb 6, 2004
22
US
I have a form created with a Combo box. What I need is when you select a certain object in the Combo box that a new field appears that allows you to enter comments.

Thanks in advance for your help.
 
in the combo box after update event procedure enter:

Private Sub Combo0_AfterUpdate()
If Combo0.Text = "Test" Then Text1.Visible = True
End Sub

David Lerwill
"If at first you don't succeed go to the pub"
 
Or if you are wanting to use more than one different text box for whatever reason, you can do the same with a Select Case Statement. Something like the following:
Code:
Private Sub Combo0_AfterUpdate()
   Dim strCombo as String
   strCombo = Combo0
  
   Select Case strCombo
      Case "Test"
          txtTest.Visible = True
          txtText1.Visible = False
          txtText2.Visible = False
          txtText3.Visible = False
      Case "Test1"
          txtTest.Visible = False
          txtText1.Visible = True
          txtText2.Visible = False
          txtText3.Visible = False
      Case "Test2"
          txtTest.Visible = False
          txtText1.Visible = False
          txtText2.Visible = True
          txtText3.Visible = False
      Case "Test3"
          txtTest.Visible = False
          txtText1.Visible = False
          txtText2.Visible = False
          txtText3.Visible = True
   End Select
End Sub



Stephen [infinity]
"Jesus saith unto him, I am the way, the truth, and the life:
no man cometh unto the Father, but by me." John 14:6 KJV
 
These are VBA coding used "AfterUpdate" event procedure.

Basically, in both cases, you hide a text box or text boxes by using the ...visible = false property of the text box. Then, depending on your approach, you display the text box.

In the first example, regardless of the "update", a text box opens. In the second, Stephen has demonstrated how you can control which text box(es) are opened depending the item selected in the combo box.

Regardless of solution...
I prefer to use
Me.Test1Txt.Visible = True

The "Me" will refer to the textbox on the current form.

There is a "gotcha" here too. You have know the name of your combo box and text box(es). To do this, open your form in "design mode", and make sure the Properties window is open - from the menu, select "View" -> "Properties". Then, select the combo or text box in question. Click on the "Other" tab. Note the value in the "Name" field -- this is the name of the text box.

I assume you are going to need more info after to consider what you want to do. So post back when you can be more specific on your requirements.

Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top