Access VBA Macro Programming

(Joao Candeias) #1

Chapter 16 The DoCmd Object


Chapter 16 The DoCmd Object


T


heDoCmdobject is a special object model in Access VBA. It is fairly simple in
structure but contains a number of methods that are very useful to an Access
developer. It is almost impossible to write a complex Access application and not
useDoCmdsomewhere.
The methods encompass all the actions available to the developer when using macro sheets
as opposed to VBA modules, so you effectively have all the macro functions built into VBA.
Some of the methods are now obsolete and no longer work in the latest versions of Access,
but are still included for backward compatibility so that it will not produce an error message
and stop your code from running. The problem of course is that it will not do what it was
intended to do.
TheDoCmdmethods are simple to use within VBA. An example would be:


DoCmd.Quit


This will exit the database completely.

DoCmd Methods


This section shows the main methods of theDoCmdobject that you will use within a VBA
application.


Beep


Beepsounds a chime on the user’s computer, provided that they have not muted the speakers!
The syntax is:


DoCmd.Beep


213

Free download pdf