Loop Through a Set of Controls

Loop Through a Set of Controls

A common requirement is to check a set of controls for a particular value or condition. Here I demonstrate two methods. The technique employed is what I call the “For Each Control in Me Controls” – it’s a technique where you interrogate each control “in/on” the Form in turn. Essentially it means you perform this code/operation on each control inside “this” (Me) Form. It’s a loop, a loop that interrogates each control in turn. One way to think about it is to imagine you have a bag full of the keys popped off your keyboard! You reach into the bag and you pick a key, you look at it and it might be the “J” key. But it’s totally random, as you reach into the bag you’ll never know which key you are going to pull out. But let’s say you wanted to find the “B” key, you would just keep pulling out them out until you found the “B”… Essentially that’s what this code does, it interrogates each control in turn, then performs an operation, but only if it’s the control you were looking for. If you only wanted to operate on one control, you might be inclined, and it might well be much simpler to use another method. However if you have no idea which control is going to meet the criteria, in other words the criteria will change from one control to another depending, then this is the best way to approach it. I mean, imagine writing an “If Then Statement” to find a different a control, with a different criteria each time! It would be a nightmare! If you’ve done it, then please let me have a look at the code, I’d love to see how complicated it actually is!

…         ..         ..            ..        ..          ..           ..     ..  ..         … 

Text Box Example

Text Box Example

Video 1  (7:34)

Text Box Example. In this particular example two text boxes can be empty but one must contain a value.

Video 1  (7:34)

Play Video

… …

Check Box Example

Check Box Example

Video 1  (7:34)

Check Box Example:- In this example the user wanted one checkbox to be checked all the time.

Please Note:- This is the same Video as above, but started at Time Index 2:54

Video 1  (7:34)

Play Video

Nice Comment From:-

Grenee said:- the video on this link provided me with exactly what I needed…

anb001 Said:- Uncle Gizmo, that was spot on. Thanks a lot.

… …