Changing attributes on multiple controls

Galaxiom

Super Moderator
Staff member
Local time
Today, 17:02
Joined
Jan 20, 2009
Messages
12,832
Is there a shorthand method of making the same set of attribute changes on multiple controls?

I realise it could be done by looping through the attribute change commands with a list of controls. However I was hoping there might be a simple syntax similar to the With Block.

Thanks
 
Hello,

I think you need something like this:

Code:
Dim ctl As Control

For Each ctl In Me.Section(acHeader).Controls
    If ctl.ControlType = acTextBox or ctl.ControlType = acComboBox then
        ctl.Value = Null
    End If
Next

This code for example will set all textbox and combobox values to Null in a form's header. If you describe what you need maybe I can come up with the exact code

Cheers

George
 
Thanks George.

I actually do have one long winded piece of code that clears a form and your concise version would work perfectly there.

Although your code is still using a loop, it is shorter than what I envisaged having to loop through a list of controls. I had not thought of addressing the whole set of controls in a section and then filtering.

I guess I could use the same principle to select particular groups of controls that have been assigned the same tag attribute.

I love it when I ask for a simple answer and get a new way of thinking about the question instead.

Thanks.
 
Hello again,

I think that using a loop is necessary for what you want to achieve. Please let us know if you find another way!

As you have probably already figured out, you can apply a set of actions to the desired objects (those having a specific attribute) by using an "if" or "select" clause within the loop.

Glad I helped

George
 

Users who are viewing this thread

Back
Top Bottom