Access VBA Macro Programming

(Joao Candeias) #1

TheFormsobject has aCountproperty that defines how many forms are open in the Access
application. The properties hold the parameters that define the object. Properties are very much
dependent on the objects they are part of, and their values can be text or numeric.
Methods are ways of executing actions based on a particular object. They provide a
shortcut to doing something on a particular object. For example, you may want to delete a
field from a table on-the-fly. To do this, use theDeletemethod on the fields collection based
on that particularTableDefobject. Similarly, theTransferSpreadsheetmethod in the
DoCmdobject transfers data between your database and a spreadsheet. The hard work has
been done for you, and all you have to do is call these methods from your code.
Take your computer, for example. It is an object and you can define properties and
methods for it. A property is a measurable aspect of an object, so for your computer you
could have the following properties:


Property Value
Make Compaq
Year 2009
RAM 8GB
Hard Disk 320GB
Processor Intel

Note that these are not all numeric. It is easy to get the idea that a property is always something
directly measurable, such as the height of an object, and is therefore always numeric. However,
properties may also be text, Boolean (True or False), graphic (in the case of pictures or icons),
or enumerated from a specific list relating to that property. They can be any data type.
Methods are words that represent actions that can be performed by the object. For your
computer, these could be


 Cold boot
 Warm boot
 Shut down
 Set up

Transferring this theory to an Access database and using the CurrentProject object as the
example, you have properties such as:


Property Description
Path The path to the Access file
FullName The full name with path of the workbook
AccessConnection The connection string for this Access database—this can be used to make a
connection from another Access database (see Chapter 19)
Name The file name of the Access database

Chapter 14: The Access Object Models 177

Free download pdf