Mike Wolfe - Looping through a set of Controls (1 Viewer)

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 13:04
Joined
Jul 9, 2003
Messages
16,282
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:

MarkK

bit cruncher
Local time
Today, 05:04
Joined
Mar 17, 2004
Messages
8,183
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
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:04
Joined
Feb 19, 2002
Messages
43,302
@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?
 

MarkK

bit cruncher
Local time
Today, 05:04
Joined
Mar 17, 2004
Messages
8,183
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.
 

June7

AWF VIP
Local time
Today, 04:04
Joined
Mar 9, 2014
Messages
5,475
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.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:04
Joined
Feb 19, 2002
Messages
43,302
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.
 

MarkK

bit cruncher
Local time
Today, 05:04
Joined
Mar 17, 2004
Messages
8,183
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.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:04
Joined
Feb 19, 2002
Messages
43,302
I think you're missing the point. We can move on:)
 

Users who are viewing this thread

Top Bottom