PDA

View Full Version : Solved: Clearing Value in ComboBox



bbsags
04-08-2013, 02:15 PM
Hi guys i am new to VBA and have the following issue, i have a combox set up but when i am using the clear command it is clearing everything from the field and not displaying anything in the box.

But if i have no clear command as per the code below then the values in the box are doubleing and so on every time the drop button is clicked.

Is there a way to prevent this?

Private Sub ComboBox2_dropbuttonclick()
With ComboBox1
If .value = "UNITY" Then
ComboBox2.AddItem ("MFC")
ComboBox2.AddItem ("HPL")
ComboBox2.AddItem ("SGL")
ComboBox2.AddItem ("Colourcoat")
End If
If .value = "QUANTUM" Then
ComboBox2.AddItem ("MFC")
ComboBox2.AddItem ("HPL")
ComboBox2.AddItem ("SGL")


End If
End With
End Sub

mdmackillop
04-08-2013, 03:22 PM
Private Sub ComboBox1_Change()
With ComboBox1
If .Value = "UNITY" Then
ComboBox2.Clear
ComboBox2.AddItem ("MFC")
ComboBox2.AddItem ("HPL")
ComboBox2.AddItem ("SGL")
ComboBox2.AddItem ("Colourcoat")
End If
If .Value = "QUANTUM" Then
ComboBox2.Clear
ComboBox2.AddItem ("MFC")
ComboBox2.AddItem ("HPL")
ComboBox2.AddItem ("SGL")
End If
End With
End Sub

bbsags
04-09-2013, 05:11 AM
hi this now clears value but when i select a value from list nothing displays in box?

mdmackillop
04-09-2013, 05:24 AM
Try this

snb
04-09-2013, 06:50 AM
Avoid populating a combobox/listbox with 'additem'



Private Sub ComboBox1_Change()

ComboBox2.list=choose(ComboBox1.listindex+1,array("MFC,HPL,SGL,Colourcoat"),array("MFC,HPL,SGL,Colourcoat"))
End Sub

bbsags
04-09-2013, 11:00 AM
Thanks guys this has worked a treat problem solved :)