Share this Page URL

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

Using Visual Basic to Automate Your Database 180 database; the CurrentProject object in the Access object model has a collection named AllForms that contains all the forms in the database. The Forms collection consists of only those forms that are currently open. The Reports collection contains all open reports, and the DataAccessPages collection contains all open data access pages. The CurrentData object in the Access object model has collection objects such as AllTables and AllQueries. The CD that accompanies this book in- cludes a diagram of the Access object model that you can view or print for reference. When you need to refer to an object in a collection, you can use syntax such as the following: Reports!ReportName Reports("reportname") Reports(index) We saw an example of the second syntax sample earlier, in the expression TableDefs (" Cam- paignExpenses"). The index refers to an item's ordered position in a collection. You often use the index to loop through the items in a collection. To refer to a control on a form, you refer to the Forms collection and then to the form before naming the control itself. Here's an example: Forms!MyForm!MyTextBox You set a property to a value using the equal sign, or you get the value of a property and assign it to a variable to use in your program. We saw this syntax in the example of the With...End With statement earlier in this chapter. Here's the code again for reference: With Me.txtProperties .Value = rs.Name .FontSize = "10" .FontBold = True End With