Mike Wolfe - Looping through a set of Controls

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 07:11
Joined
Jul 9, 2003
Messages
16,886
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
 
@MarkK Seems like extra work to take something which is already an array and then move it into a different array where you loop through it or am I missing something?
 
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.
 
If data is in a table AND you want to process it MULTIPLE times, I would guess that copying the data into an array MIGHT make the process more efficient but since external data reads are buffered, I would not bet much money on it. If the data you need is already in the buffer, no round trip to the server is required. It is simply a memory access which is already very efficient or at worst a local disk access. But copying data from one array into a different array sounds more like an extra step than an improvement.

The newest hard drives that have no rotating disks should be almost as fast as reading from memory. I haven't done a detailed analysis in years and technology has evolved during that time. Someone with a lot of different device types would need to do the analysis.
 
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.
 
I think you're missing the point. We can move on:)
 

Users who are viewing this thread

Back
Top Bottom