Code Examples

All of the code examples here are to demonstrate the use of particular RunCommand Constants. They may not be the best or most efficient method of achieving the end result. In fact for some you should be able to find better ways. The use of SendKeys, for example, can cause problems of its own. Have a look at any of the FAQ sites to find out about these.

I have tried to test all the code examples and include error trapping where approrpiate. If you find any mistakes or can suggest any improvements to the examples please E Mail me Cecil Butts. I would also be pleased to include any examples that you may have that use RunCommand constants that I have not already got covered.

Some of the code on this site appears by permission of the person who first wrote it. Please feel free to use the code but observe the copyright notice in the examples. Other examples are from Microsoft sources. The exact source of each piece of code is displayed above the code concerned. The RunCommand constant is highlighted within the code.

Constants UsedExample
acCmdAdvancedFilterSortSelect a Saved Filter
acCmdApplyFilterSortSelect a Saved Filter
acCmdAppMaximizeResize The Access Window
acCmdAppMinimizeResize The Access Window
acCmdAppMoveMove The Access Window
acCmdAppRestoreResize The Access Window
acCmdCloseClose Open Form
acCmdCompactDatabaseCompact Database
acCmdCompileAndSaveAllModulesCompile A Database
acCmdCopyCopy To New Record
acCmdCopyHyperlinkCopy Hyperlink
acCmdCreateShortcutCreate Desktop Shortcut
acCmdDebugWindowDisplay Debug Window
acCmdDeleteRecordDelete A Record
acCmdDesignViewAdd Or Remove Form Headers
acCmdEditHyperlinkEdit Hyperlink
acCmdEncryptDecryptDatabaseEncrypt/Decrypt File
acCmdExitQuit Access
acCmdFilterBySelectionFilter By Selection
acCmdFindOpen Find Dialog
acCmdFitToWindowZoom Print Preview
acCmdFontDisplay the Font Dialog 
acCmdFormHdrFtrAdd Or Remove Form Headers
acCmdFormViewAdd Or Remove Form Headers
acCmdHyperlinkDisplayTextEdit Hyperlink Text
acCmdInvokeBuilderInvoke the Buiilder
acCmdLoadFromQuerySelect a Saved Filter
acCmdMoreWindows Display List of Open Windows
acCmdNewObjectAutoFormCreate a New AutoForm
acCmdNewObjectModuleCreating a New Module
acCmdNewObjectAutoReportCreate a New AutoReport
acCmdNewObjectQueryStart a New Query
acCmdOLEObjectDefaultVerbActivate OLE Field 
acCmdOpenHyperlinkOpen Hyperlink
acCmdOpenNewHyperlinkOpen Hyperlink In New Window
acCmdOptionsOpen Options Dialog
acCmdOutPutToExcelExport to Excel
acCmdPasteAppendCopy To New Record
acCmdPrintPrint Dialog in Runtime Environment
acCmdPrintPreviewPrint Preview an Object 
acCmdRefreshRefresh A Table
acCmdRelationshipsSave Relationships Layout
acCmdRepairDatabaseRepair External Database
acCmdSaveAdd Or Remove Form Headers
Save Relationships Layout
acCmdSaveAsDisplay Save As Choice 
acCmdSelectRecordCopy To New Record
Delete A Record
acCmdSizeToFitFormAdd Or Remove Form Headers
acCmdSpellingSpell Checking in Runtime Environment
acCmdUndoAdd to a Listbox
acCmdUserAndGroupAccountsDisplay User and Group Accounts Information
acCmdViewCodeCompile A Database
acCmdWindowHideHide An Object
Mail Merge with Word
Select a Saved Filter
acCmdWindowUnhideShow Unhide Dialog
acCmdWordMailMergeMail Merge with Word
acCmdZoom10Zoom Print Preview
acCmdZoom100Zoom Print Preview
acCmdZoom150Zoom Print Preview
acCmdZoom200Zoom Print Preview
acCmdZoom25Zoom Print Preview
acCmdZoom50Zoom Print Preview
acCmdZoom75Zoom Print Preview
acCmdZoomBoxDisplay Field in Zoombox