Clearing all comboboxes on a form

G

Guest

Anyone know how to clear all unbound comboboxes on a form with VBA? I don't
even know how to do one. Maybe remove item. Plus, sometimes it populates items
then leaves them in the combobox in the properties window
 
A

Allen Browne

This assumes the code goes somewhere in the module of the form, e.g. in the
Click event of a comand button on the form:

Dim ctl As Control
For each ctl in Me.Controls
If ctl.ControlType = acCombobox Then
If len(ctl.ControlSource) = 0 Then
ctl.Value = Null
End If
End If
Next
Set ctl = Nothing
 
G

Guest

Thanks. Thats works great. The only problem I see is that sometimes the
rowsource doesn't clear. Do I have to clear them with literals, ex:
me.combo1.rowsource = ""
me.combo2.rowsource = ""

I don't know why they 'stick'
Access forms have a lot of annoying features like this.
 
A

Allen Browne

You should be able to clear the combo's Value (so the combo is blank -
nothing chosen), without needing to mess with its RowSource (the items in
the list to choose from).
 

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