Hiding all combo boxes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form containing an option group with corresponding combo boxes that
prompt the user through criteria when a certain option is selected. I want
all the combo boxes to be hidden both on form load and also when changing
options. I have written a procedure using
Forms![Reporting]!cboComboBox.Visible = False for each combo box on the form
but this is getting quite large. Is there a way to write some code to have
all combo boxes hidden at once. Then I can call the function whenever I need
it. I tried a For..Each statement but my syntax was way off.

Any help would be appreciated.

Thanks...
 
If you put the subroutine inside the form's module:

Private Sub ComboBoxVisibility(MakeVisible As Boolean)
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acComboBox Then ctl.Visible = MakeVisible
Next ctl
End Sub
 
Sub Hide_The_Boxes(frm As Form, blnShow as Boolean)
' frm is the name of the form
' blnShow - Visible = True, Not Visible = False

Dim ctl As Control

For Each ctl In frm.Controls
If ctl.ControlType = acComboBox Then
ctl.Visible = blnShow
End If
Next

End Sub

This will get you started, If you want to pass it specific control names,
then you could use a Parameter Array to pass all the contorl names and look
in the array to match the control name (ctl.name) before changing it. This
could be a function you could use in any form
 
Worked like a charm. Thank you...

Klatuu said:
Sub Hide_The_Boxes(frm As Form, blnShow as Boolean)
' frm is the name of the form
' blnShow - Visible = True, Not Visible = False

Dim ctl As Control

For Each ctl In frm.Controls
If ctl.ControlType = acComboBox Then
ctl.Visible = blnShow
End If
Next

End Sub

This will get you started, If you want to pass it specific control names,
then you could use a Parameter Array to pass all the contorl names and look
in the array to match the control name (ctl.name) before changing it. This
could be a function you could use in any form

Ken D. said:
I have a form containing an option group with corresponding combo boxes that
prompt the user through criteria when a certain option is selected. I want
all the combo boxes to be hidden both on form load and also when changing
options. I have written a procedure using
Forms![Reporting]!cboComboBox.Visible = False for each combo box on the form
but this is getting quite large. Is there a way to write some code to have
all combo boxes hidden at once. Then I can call the function whenever I need
it. I tried a For..Each statement but my syntax was way off.

Any help would be appreciated.

Thanks...
 
Back
Top