PDA

View Full Version : Solved: Problems with my Combo Boxes



wildpianist
10-29-2007, 12:55 PM
What am I doing wrong?

I'm pretty new to all this with "IF" "ELSE" "END IF" etc etc

Basically what I am looking to do is when one clicks on ComboBox1 it drops down a list lets say "1" "2" and "3" however when one clicks "1" it then Shows another ComboBox ("ComboBox11") (thats already seen) and when one selects "2" from ComboBox1 it then changes "ComboBox11" completely and shows a list completely different to the other one and then same when someone clicks "3"

This is what I've done so far - Apologies for the bad code


Private Sub ComboBox1_Change()
With Me.cboType
If .Value = "1" Then
ComboBox11.Visible = True
ComboBox1.Visible = False
'ComboBox1 being the box that is already visable'

If Me.cboType.Value = "2" Then
ComboBox12.Visible = True
ComboBox11.Visible = False
ComboBox1.Visible = False

If Me.cboType.Value = "3" Then
ComboBox13.Visible = True
ComboBox12.Visable = False
ComboBox11.Visable = False
ComboBox1.Visable = False

End If
End If
End If
End With
End Sub




Apologies again for the bad code and this is probably why my code is not working :help

As I said I'm not too sure how I get my ELSE's in there either, or where to put them

Hopefully you guys can help me : pray2:

Dave

Bob Phillips
10-29-2007, 01:08 PM
Untested



Private Sub ComboBox1_Change()
With Me.cboType
If .Value = "1" Then
ComboBox11.Visible = True
ComboBox1.Visible = False
'ComboBox1 being the box that is already visable'

ElseIf Me.cboType.Value = "2" Then
ComboBox12.Visible = True
ComboBox11.Visible = False
ComboBox1.Visible = False

ElseIf Me.cboType.Value = "3" Then
ComboBox13.Visible = True
ComboBox12.Visable = False
ComboBox11.Visable = False
ComboBox1.Visable = False
End If
End With
End Sub

wildpianist
10-29-2007, 01:23 PM
:bow:

Absolute Genius!!!!!

I was close(ish) lol

Thanking you

Dave

Bob Phillips
10-29-2007, 02:07 PM
Well you were actually, it was just that you nested the Ifs rathere than made them If ... Else.

Your way, the second If never got exercised unless the first one passed, in which case it failed anyway.

wildpianist
10-29-2007, 02:11 PM
Lol - D'Oh!

:D