Databases Reference
In-Depth Information
VBA and DAO offer a wide variety of object data types . There is a slight difference in
syntax when declaring and setting an object variable, as opposed to a standard variable.
For instance, here is an example using the Database object type. Note that the full
pathname of the LIBRARY database on my PC is d:\dbase\library.mdb :
Dim dbLibrary as Database
Set dbLibrary = "d:\dbase\library.mdb"
In general, the syntax is:
Dim objectVariable as ObjectDataType
Set objectVariable = ObjectName
Note that the only difference between setting object variables and setting standard
variables is the keyword Set . However, this minor syntactic difference belies a much
more significant difference between standard variables and object variables.
In particular, a standard variable can be thought of as a name for a location in the
computer's memory that holds the data. For instance, in the code:
Dim intVar As Integer
intVar = 123
the variable intVar is a 4-byte memory location that holds the integer value 123. Figure
14-1 illustrates the variable intVar . (Actually, the 4-byte memory location holds the
value 123 in binary format, but that is not relevant to our discussion.)
Figure 14-1. An example of the intVar variable
Of course, if we were to write:
Dim intVar As Integer
Dim intVar2 As Integer
intvar = 123
intVar2 = intVar
intVar2 = 567
we would not expect the last line of code to have any effect upon the value of the variable
intVar , which should still be 123.
On the other hand, an object variable is not the name of a memory location that holds the
object's “value,” whatever that means. Rather, an object variable holds the address of the
area of memory that holds the object. Put another way, the object variable holds a
reference to, or points to, the object. It is therefore called a pointer variable . The idea is
Search WWH ::




Custom Search