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

Step through all items of a collection using a For…Each loop

From the course: Access: VBA

Start my 1-month free trial

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…

Contents