Microsoft Office Tutorials and References
In Depth Information
Understanding Objects and Collections
Table 4-3
Common Types for Object Variables
Object Type
Use to Declare
AccessObject
Any type of Access object in AllForms , AllReports ,
and other collections
Form
A form
Report
A report
Control
A control on a form or report
Property
A property of an object
A group of records (see Chapter 5 of this minibook)
Recordset
At the highest level of the object model, you can use the AllForms,
AllReports, and other collections contained within the CurrentProject
object to refer to any form or report — even forms and reports that aren’t open.
Each object in those collections has a general type called AccessObject.
For a detailed explanation of the CurrentProject object and the
collections that it supports, look up the CurrentProject object in Visual Basic
Editor’s help system, and examine the CurrentProject Object link.
If you want to create a reference to a form named Products Form, in code,
and give that form a short variable name like myForm, declare myForm as an
AccessObject. Then set that variable’s value to the form by using the syntax
Set myForm = CurrentProject.AllForms(“FormName”), as follows:
Dim myForm As AccessObject
Set myForm = CurrentProject.AllForms(“Products Form”)
After the code runs, the variable named myForm refers to the form named
Products Form.
Naming conventions for object variables
In this chapter, we use the letters my at the
start of variable names just to provide some
consistency. Some programmers, however,
follow other naming conventions, replacing the
letters my with a tag that represents the object
type to which the variable refers. If an object
variable refers to an AccessObject ,
programmers may use obj as the first letters of
an object variable name, as in Dim objForm
as AccessObject . Or they may use ctl as
the first letters of an object variable that refers
to a control, as in Dim ctlProductID as
Control .
Naming conventions are especially useful in
large projects in which many programmers work
with code, because the conventions help identify
the object types that variables refer to. Naming
conventions are optional, though, so don’t feel
that you must use them in your own code.
Search JabSto ::




Custom Search