Mike Wolfe - Looping through a set of Controls

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 15:02
Joined
Jul 9, 2003
Messages
17,345
Mike Wolfe's latest newsletter contains and interesting section on looping through a set of controls:- "7 Ways to Loop Through Controls on a Microsoft Access Form" Here's the Link:- https://nolongerset.com/loop-through-controls/

The 8th way to Loop through a set of Controls
There's a method he did not cover, you can modify the control name. A normal control name might be "txtMyTextBox"... To use this method you add an extra character between the the prefix and the control name like this:- "txtXMyTextBox" and use the "X" to identify the group of controls that you want to modify.

The 9th way to Loop through a set of Controls
There's another method I developed. You put a rectangle around the group of controls you want to work on. Your code will only affect the controls inside the rectangle. I call it the "Nifty Container". You can read more about it here:-

Nifty Container​


Nifty Container - YouTube Video​


If you would like a free copy of the "Nifty Container" then send me a message using this forums private messaging system and I will send you a coupon code allowing you to download it for free...
 
Last edited:
What I usually do, maybe a 10th way, is define a local array, and explicitly stuff it with the controls I want in the group, like...
Code:
Private ctrls_

Property Get MyControls
    If IsEmpty(ctrls_) Then ctrls_ = Array(Me.cmdFirst, Me.cmdPrev, Me.tbRecordNumber, Me.cmdNext, me.cmdLast)
    MyControls = ctrls_
End Property

Sub SetEnabled(State as Boolean)
    Dim ctrl As Control

    For Each ctrl in MyControls
        ctrl.Enabled = State
    Next
End Sub
 
Hey Pat, I understand the thread to be about how to define a subset of controls. I offer a way to do that. Maybe I am missing something.
 
I suppose if you want to interact with the same group more than once during a process, the array (or custom collection or dictionary) would be useful.
 
There is no mention in this thread of data in a table. This thread is about working with a subset of controls on a form.
 

Users who are viewing this thread

Back
Top Bottom