Share this Page URL

Chapter 5. Using Visual Basic to Automat... > Using an Object Model - Pg. 183

Using Visual Basic to Automate Your Database Debug.Print "The current object is " & Application.CurrentObjectName End Sub 183 The first For Each statement displays the Name property for each form in the CurrentProject object's AllForms collection. The next For Each statement displays the name of each form in the Forms collection. If no forms are open in the database when you run this code, nothing will be displayed as the result of this statement. The next line uses the Count property of the AllTables collection to display the number of tables in the database. In the last two sets of statements, the procedure outputs the Path property of the current database ( CurrentProject.Path ) and then the name of the object that's selected in the Database window ( Application.CurrentObjectName ). To view the output from this procedure, open modDemonstrations and locate the AccessObjects procedure. Open the Immediate window, and in it type AccessObjects. Then press Enter. You'll see something similar to the output shown in Figure 5-6.