Assigning Objects to Variables
Assign objects to a variable by using the Set statement.
Generic Object Types
One advanced VBA programming technique is the use of generic object types. There are two types of generic objects specified by the declaration keywords Object and Control.
The TypeOf Operator
Use the TypeOf operator to identify an object's type. It only works in the If Then structure with form:
If TypeOf <Object> is <ClassName> Then
<stuff>
End If
Note that Access 97 objects have a ControlType property.
The Concept of Collections
Collections are similar to arrays. Collections are superior to arrays in many ways. Collections can have unique string names as well as the numerical index used in arrays.
Iterating through the Members of a Collection
Use the For Each...Next structure. There is no need to determine the number of elements in the collection.
Writing Custom Properties
Declaring a variable Public in a form at module level creates a user-defined property for this form. By using Property Get and Property Let, we can add more functionality than just setting a public property. We can associate a procedure with the manipulation of the property.
Please see "Customizing a Form" (pg. 45) for further discussion.
Object-Valued Properties and the Property Set Statement
An object-valued property contains object instead of an integer, boolean, long, etc. You can create custom properties that return objects using the Property Set keywords.
When to Use Property Procedures and Public Functions
Public variables do not have all the functionality of property procedures. Property procedures also have an advantage over public functions. Functions can return values but they do not store the current state of the values they are associated with.
VBA Classes
Property procedures go a long way to make the classes used in VBA actually useful. VBA Classes are an aid for programmers, allowing them to package their code and add them to projects and be recognized in the object browser.
To see classes in action please see "Coding Access 97 Class Modules" (pg. 50).