Access VBA Macro Programming

(Joao Candeias) #1
This provides a very easy way of making a sound, although it is very limited in what it can
do. If you need more flexibility, see Chapter 20 on API calls. API calls can also be used to
play a variety of sounds.

Close
Closeis used to close an object, usually a form or report, although other object types can be
specified. It has three optional parameters. The syntax is:

Docmd.Close (ObjectType,ObjectName,Save)

ObjectType is an acObjectType constant representing the type of object to close. Examples
are acForm and acReport. The object name is the name of the form or report to be closed, and
Save is an acCloseSave constant that specifies whether to save the object or not.
This method is normally run on a form or report module of a “Close” button, so the
optional parameters are not required. Although the user may be able to close the form by
clicking the X in the top-right corner, you may want your code to have more control over the
closing of the form.

CloseDatabase
CloseDatabaseis the same as if you had clicked the Microsoft Office button in Access and
then clicked the “Close Database” button. It has no parameters.

DoCmd.CloseDatabase

Hourglass
TheHourglassmethod lets you turn the cursor into an hourglass (or whatever icon is chosen
to show a running procedure), or turn it back into the cursor. This is very useful because the
hourglass cursor does not always appear when VBA code is running, and users like to have
some reassurance that something is happening.
The syntax is:

DoCmd.Hourglass True

This turns the hourglass mouse pointer on. To turn it off, use:

DoCmd.Hourglass False

HourglassOn is True or False to denote whether to show the Hourglass.
If you switch the Hourglass on, remember to switch it back to a normal cursor afterwards.
Also, I have found that if a piece of code crashes before the cursor is switched back, it will
give the user the impression that everything is still running when it is not.

Maximize
Maximizewill, just as its name implies, maximize the active window as if the user had clicked
the Maximize button on it. It is normally used in the Open or Activate event of forms and
reports to ensure that the window fits on the user’s screen. Users frequently have different

214 Microsoft Access 2010 VBA Macro Programming

Free download pdf