How do i Show/Hide Combo based on the answers of another combobox?

G

Guest

Hi All,

I'm trying to write code that will so and hide a combo box depending on the
answer you select in another combo box.

Here's what i have so far:

Private Sub Item_AfterUpdate()

On Error Resume Next

Select Case Item.Visible

Case "Computer"
Computer_Name.Visible = True

Case "Projector"
Computer_Name.Visible = False

Case "Monitor"
Computer_Name.Visible = False

Case "Smartboard"
Computer_Name.Visible = False

Case "Sound System"
Computer_Name.Visible = False

Case "Camera"
Computer_Name.Visible = False

End Select

End Sub

I want it to only show the other combo box when you select "Computer" in the
other combo box. The code i've wrote does show and hide the combo box but it
does this if you select any option.

Hope this makes sense.

Thank You
 
G

Guest

Try taking the .Visible part away from your select statement.

Select Case Item


Good Luck!
Steve.
 
G

Guest

Thanks for the comment, unfortunately it's not still playing ball. Any more
ideas?

Thanks
 
G

Guest

I'd try using the "me" keyword:-

Select case me.item

The me keyword is very useful have a look in the VB help for what it means.
 
G

Guest

Thank You John,

It's still showing the combo box if you select any option.

Is "Case" the right command to be using of should i use an "If" command?

Cheers

Dave
 
P

Powderfinger

What is the ColumnWidths and ColumnCount properties of your ITEM combo?

If ColumnWidths is something like "0";1";" then this means that there is an
invisible field, usually a numeric primary index, so you would have to do
something like this :

If Me.Item.Column(1) = "Computer" Then
Me.Computer_Name.Visible = True
Else
Me.Computer_Name.Visible = False
End If

This works unless someone deletes the value in the ITEM field. You'll
usually get a null error. In which case you are better off doing this:


If Len(Trim(Me.Item.Column(1) & vbNullString)) > 0 Then

If Me.Item.Column(1) = "Computer" Then
Me.Computer_Name.Visible = True
Else
Me.Computer_Name.Visible = False
End If

End If
 
G

Guest

Yey! It's worked. Thank You Very Much. I can get round to finishing the rest
of the database now. Expect more posts from me ;-)

Thanks Again

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top