Sandra Smith
asked on
Remove items from a combo in code
I have a combo box that its contents depends on what a user selects in the first combo. These are boxes located on a data entry fform bound to a table. So, depending on what the user selects in the first combo box, the second combo needs to have its data dynamically change. I tried the below, but I keep getting a Compile Error User Defined Type Note defined. All I want is to clear the (*)*I^&%% combo box. I thought it woudl be so simple!
Public Sub ClearSecondary(ctl As Combo)
'Clears Secondary combo boxes so there is no left over item
Dim i As Integer
For i = 1 To ctl.Count
ctl.RemoveItem 0
Next i
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
HA! I got it to work. I changed it to the following.
Public Sub ClearSecondary()
'Clears Secondary combo boxes so there is no left over item
Dim i As Integer, ctl As ComboBox
Set ctl = Forms!frmWeeklyActivities.cboSecondary
For i = 1 To ctl.ListCount
'Remove an item from the ListBox.
ctl.RemoveItem 0
Next i
End Sub
ASKER
You were kind enought to responsd, thank you.
Ohhh, you're doing it THAT way.
don't ya love how Access handles combo boxes? <g>
That way was such a pain, I just wrote functions built a value list string and set it to that.
Anyway, same thing applies. Set the rowsource to a blank string. (then set it back to the function name later)
don't ya love how Access handles combo boxes? <g>
That way was such a pain, I just wrote functions built a value list string and set it to that.
Anyway, same thing applies. Set the rowsource to a blank string. (then set it back to the function name later)
try just setting the rowsource to a blank string then back to it's previous value. two lines of code.
ASKER
Open in new window