If I have several objects on a form and I wish to make them visible/invisible how best can I do this using a For Next loop?
E.g. lblCustomer1, lblCustomer2 I deliberately placed numbers on the end in order to set that using the loop controller, but access doesn't like that and prefers me to type in the hard name, which would mean doing the same line of code 40 times or so.
Any tips or suggestions on this would be gratefully accepted.
You can try something like this, which will loop through all the objects on your form and perform an action depending on the control type and/or a control tag value you've entered for certain controls (i.e., entering 1 as the tag for a group of controls of different types that you want to hide).
Dim ctl as Control
For Each ctl in Me.Controls
'check the control type and do some action
Select Case ctl.ControlType
'or check the control tag and do some action
Select case ctl.Tag
'Destroy the ctl object
Set ctl = Nothing
If you're not using it in a form module, just replace Me.Controls with Forms!formname!Controls.
You can get a list of the acControlType enumeration constants in the VBA object browser (press F2 while in the VBA editor and search for "acControlType")