Part IV: Professional Database Development
1056
l (^) SetWarnings: This action turns the system messages on or off using the Warnings On
argument. When running action queries, you’ll be prompted to make sure you want to
run the action query, asked if it’s okay to delete these 58 records, and then asked again for
the next action query. Set Warnings On to No at the beginning of the macro to turn these
messages off — assuming you’ll click OK or Yes in each message box. Set it back to Yes at
the end of the macro.
Again, don’t forget to turn warnings back on at the conclusion of the macro. Once warn-
ings are turned off, the user won’t get confirmation messages from Access on important
actions like record deletions until warnings are re-enabled.
l Echo: This action shows or hides the results of a macro while it runs using the Echo On
argument. Set it to No to hide the results of the macro or Yes to show the results. Set the
Status Bar Text argument to give the user an indication of what’s happening. This is
useful in longer-running macros to know where in the process the macro is.
The Echo command “freezes” the screen so that the user isn’t aware of activities per-
formed by the macro. Echo is much like Hourglass and SetWarnings — be sure
to restore the Echo status to Yes so that Access resumes its normal appearance. If
Echo is not turned back on, the user may think the application has “locked up” because
of a problem.
l (^) OpenQuery: This action is the heart of the mcrBackupContactsAndProducts
macro. OpenQuery opens a select or crosstab query or runs an action query. The Query
Name argument contains the name of the query to open or run. The View argument lets
you pick the view — Datasheet, Design, Print Preview, PivotTable, or PivotChart — for a
select or crosstab query. The Data Mode argument lets you choose from Add, Edit, or
Read Only to limit what users can do in a Select query. The View and Data Mode argu-
ments are ignored for action queries.
The heart of the macro is the four OpenQuery actions that run the four action queries.
qryDeleteContactsBackup and qryDeleteProductsBackup clear the contents of
tblContacts_Backup and tblProducts_Backup, so the current data can be copied into
them. qryAppendContactsBackup and qryAppendProductsBackup append data from
tblContacts and tblProducts into the backup tables.
You could easily build this macro just using the four OpenQuery actions, but running it would
be cumbersome, especially if one of the queries took a few minutes — or hours — to run. Use
the Hourglass, SetWarnings, Echo, and MessageBox actions to eliminate the need for
user interaction and to let the user know what’s happening and when the macro has completed
its activity.