ACC: Sample Macro for Repair/Compact OperationsID: Q100923
|
Moderate: Requires basic macro, coding, and interoperability skills.
This article demonstrates a sample macro that repairs and compacts a
database.
The sample macro in this article automates the process of compacting and
repairing a database. It repairs a database called MYDB, and compacts it to
a new database called NewDB. The macro will only prompt for information if
the name of the database it is compacting to already exists.
NOTE: The macro must be run from a different database than the one you want
to repair and compact.
In Microsoft Access 97, create the following macro:
Macro Name Action
----------------------------
Test SetWarnings
SendKeys
RunCommand
SendKeys
RunCommand
SetWarnings
Test Actions
-----------------------------------------
SetWarnings
WarningsOn: No
SendKeys
Keystrokes: Mydb.mdb{enter}
Wait: No
RunCommand
Command: RepairDatabase
SendKeys
Keystrokes: Mydb.mdb{enter}NewDB{enter}
Wait: No
RunCommand
Command: CompactDatabase
SetWarnings
Warnings On: Yes
Macro Name Action
----------------------------
Test SetWarnings
SendKeys
DoMenuItem
SendKeys
DoMenuItem
SetWarnings
Test Actions
-----------------------------------------
SetWarnings
WarningsOn: No
SendKeys
Keystrokes: Mydb.mdb{enter}
Wait: No
DoMenuItem
Menu Bar: Startup
Menu Name: Tools
Command: Database Utilities
SubCommand: Repair Database
SendKeys
Keystrokes: Mydb.mdb{enter}NewDB{enter}
Wait: No
DoMenuItem
Menu Bar: Startup
Menu Name: Tools
Command: Database Utilities
SubCommand: Compact Database
SetWarnings
Warnings On: Yes
Macro Name Action
----------------------------
Test SetWarnings
SendKeys
DoMenuItem
SendKeys
DoMenuItem
SetWarnings
Test Actions
------------------------------------------------------------
SetWarnings
WarningsOn: No
SendKeys
Keystrokes: MYDB.MDB{enter}
Wait: No
DoMenuItem
Menu Bar: Startup (in Microsoft Access version 1.x = Init)
Menu Name: File
Command: Repair Database
SendKeys
Keystrokes: MYDB.MDB{enter}NewDB{enter}
Wait: No
DoMenuItem
Menu Bar: Startup (in Microsoft Access version 1.x = Init)
Menu Name: File
Command: Compact Database
SetWarnings
Warnings On: Yes
For more information about command line, CompactDatabase, or RepairDatabase search the Help Index for "command line", "CompactDatabase", or "RepairDatabase."
Keywords : kbusage
Version : 1.0 1.1 2.0 7.0 97
Platform : WINDOWS
Issue type : kbinfo
Last Reviewed: March 23, 1999