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

Open in new window

Sandra SmithRetiredAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aesmikeCommented:
This isn't quite like VB.
What is the rowsource for the second combo box? if it's a value list, just set the rowsource equal to an empty string.  this clears the list.  If the row source is a query then requry the control.  (ctl.requery)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sandra SmithRetiredAuthor Commented:
Neither, it is a list I have in a public sub that, depending on the first combo, is call to populate the second combo.  Actually, i got the code straight from microsoft's examples.  I changed it to below, but now the count is giving me problems.
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.Count
               'Remove an item from the ListBox.
               ctl.RemoveItem 0
           Next i
End Sub

Open in new window

0
Sandra SmithRetiredAuthor Commented:
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

Open in new window

0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Sandra SmithRetiredAuthor Commented:
You were kind enought to responsd, thank you.
0
aesmikeCommented:
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)

0
aesmikeCommented:
try just setting the rowsource to a blank string then back to it's previous value.  two lines of code.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.