Cycle Through All ComboBoxes On A from, without using the name?

tembenite

Registered User.
Local time
Today, 17:59
Joined
Feb 10, 2005
Messages
38
Is there an array of all the comboboxes on a form, or any other means to cycle through all the comboboxes on that form without using the names of the comboboxes?

I'm trying to create a function that can be used by several different forms that would cycle through all the combo boxes and run a few commands based upon the combobox values. While I could use a workaround (eg. Storing refs to all the different combo boxes on the page, and passing that array as part of the arguments in this function), it would of course be a ton easier if there was something already built into VBA. Thanks.
 
Code:
Dim ctl As Control

For Each ctl In Me.Section(acHeader).Controls
    If ctl.ControlType = acComboBox Then
         Debug.Print ctl.Name 'or do other stuff.....
    End If
Next ctl

hth,
 
Thanks!

That worked great! Thanks!
 
Requery all ComboBoxes & Subforms - Select the only option

For anyone who might find it useful. This is the resulting code I created to be used on a ton of my forms. It requeries all ComboBoxes, and subforms. If the combobox only has one choice, it then selects that choice.

--------------------------

Function RefreshIT()
Dim ctl As Control
For Each ctl In Screen.ActiveForm.Controls
If ctl.ControlType = acComboBox Then
ctl.Requery
If ctl.ListCount = 1 Then ctl = ctl.ItemData(0)
End If
If ctl.ControlType = acSubform Then ctl.Requery
Next ctl
End Function
 

Users who are viewing this thread

Back
Top Bottom