From the course: Access: VBA
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Step through all items of a collection using a For…Each loop
From the course: Access: VBA
Step through all items of a collection using a For…Each loop
- [Instructor] The Access object model groups objects of the same type into collections. For example, the data base object contains the Forms collection which contains a form object for each open form in the database. If you want your code to affect every member of a collection or an array, you can use a for-each loop to interact with each element using the code that you create. I'll demonstrate how to do that in this movie. I have opened the course database and I have the Categories and Customers Forms open so that they will be present in the Forms collection when we work with it later. To create some VBA code, I need to press ALT + F11 to move to the Visual Basic editor, so I'll do that now. And then I want to add a new code module so I'll go to the Insert tab of the ribbon and click Module. Now on my code module I can define an array and move through it using for-each. So I'll start with Sub and I'll call in ForDemo. I'm not passing any arguments so I will type an open and closed…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Repeat a task using a For…Next loop5m 5s
-
(Locked)
Step through all items of a collection using a For…Each loop4m 59s
-
(Locked)
Repeat a task using a Do…While loop5m 32s
-
(Locked)
Perform a task when conditions are met using an If…Then statement6m 20s
-
Select actions using a Case statement6m 17s
-
(Locked)
-
-
-
-
-
-
-