Class DoCmd (Access VBA)

You can use the methods of the DoCmd object to run Microsoft Office Access actions from Visual Basic. An action performs tasks such as closing windows, opening forms, and setting the value of controls.

Class Application gives access to class DoCmd.

Methods

Close - The Close method carries out the Close action in Visual Basic.


Private Sub cmdCloseForm_Click() 
On Error GoTo Err_cmdCloseForm_Click 
 
 DoCmd.RunCommand acCmdSaveRecord 
 DoCmd.Close 
 
Exit_cmdCloseForm_Click: 
 Exit Sub 
 
Err_cmdCloseForm_Click: 
 MsgBox Err.Description 
 Resume Exit_cmdCloseForm_Click 
 
End Sub

FindRecord - The FindRecord method carries out the FindRecord action in Visual Basic.


DoCmd.FindRecord "Smith",, True,, True

GoToRecord - The GoToRecord method carries out the GoToRecord action in Visual Basic.


DoCmd.GoToRecord acDataForm, "Employees", acGoTo, 7

OpenForm - The OpenForm method carries out the OpenForm action in Visual Basic.


DoCmd.OpenForm "Employees", , ,"LastName = 'King'"

OpenQuery - The OpenQuery method carries out the OpenQuery action in Visual Basic.


DoCmd.OpenQuery "Sales Totals Query", , acReadOnly

OpenReport - The OpenReport method carries out the OpenReport action in Visual Basic.


DoCmd.OpenReport "Sales Report", acViewNormal, "Report Filter"

OutputTo - The OutputTo method carries out the OutputTo action in Visual Basic.


DoCmd.OutputTo acOutputTable, "Employees", _ 
 acFormatRTF, "Employee.rtf", True

TransferDatabase - The TransferDatabase method carries out the TransferDatabase action in Visual Basic.


DoCmd.TransferDatabase acImport, "Microsoft Access", _ 
    "C:\My Documents\NWSales.mdb", acReport, "NW Sales for April", _ 
    "Corporate Sales for April"

TransferSpreadsheet - The TransferSpreadsheet method carries out the TransferSpreadsheet action in Visual Basic.


DoCmd.TransferSpreadsheet acImport, 3, _ 
 "Employees","C:\Lotus\Newemps.wk3", True, "A1:G12"

TransferSQLDatabase - Transfers the entire specified Microsoft SQL Server database to another SQL Server database.


DoCmd.TransferCompleteSQLDatabase _ 
 Server:="MainOffice", _ 
 Database:="Inventory", _ 
 UseTrustedConnection:=True, _ 
 TransferCopyData:=False 

TransferText - The TransferText method carries out the TransferText action in Visual Basic.


DoCmd.TransferText acExportDelim, "Standard Output", _ 
    "External Report", "C:\Txtfiles\April.doc"

AddMenu - The AddMenu method carries out the AddMenu action in Visual Basic.

ApplyFilter - The ApplyFilter method carries out the ApplyFilter action in Visual Basic.

Beep - The Beep method carries out the Beep action in Visual Basic.

BrowseTo - The BrowseTo method performs the BrowseTo action in Visual Basic.

CancelEvent - The CancelEvent method carries out the CancelEvent action in Visual Basic.

ClearMacroError - Removes information about an error that is stored in the MacroError object.

CloseDatabase - Closes the current database.

CopyDatabaseFile - Copies the database connected to the current project to a Microsoft SQL Server database file for export.

CopyObject - The CopyObject method carries out the CopyObject action in Visual Basic.

DeleteObject - The DeleteObject method carries out the DeleteObject action in Visual Basic.

DoMenuItem - Displays the appropriate menu or toolbar command for Microsoft Access.

Echo - Carries out the Echo action in Visual Basic.

FindNext - The FindNext method carries out the FindNext action in Visual Basic.

GoToControl - The GoToControl method performs the GoToControl action in Visual Basic.

GoToPage - Carries out the GoToPage action in Visual Basic.

Hourglass - The Hourglass method carries out the Hourglass action in Visual Basic.

LockNavigationPane - You can use the LockNavigationPane method to prevent users from deleting database objects that are displayed in the navigation pane.

Maximize - The Maximize method carries out the Maximize action in Visual Basic.

Minimize - The Minimize method carries out the Minimize action in Visual Basic.

MoveSize - The MoveSize method carries out the MoveSize action in Visual Basic.

NavigateTo - You can use the NavigateTo method to control the display of database objects in the navigation pane.

OpenDataAccessPage - The OpenDataAccessPage method carries out the OpenDataAccessPage action in Visual Basic.

OpenDiagram - The OpenDiagram method carries out the OpenDiagram action in Visual Basic.

OpenFunction - Opens a user-defined function in a Microsoft SQL Server database for viewing in Microsoft Access.

OpenModule - The OpenModule method carries out the OpenModule action in Visual Basic.

OpenStoredProcedure - The OpenStoredProcedure method carries out the OpenStoredProcedure action in Visual Basic.

OpenTable - The OpenTable method carries out the OpenTable action in Visual Basic.

OpenView - The OpenView method carries out the OpenView action in Visual Basic.

PrintOut - The PrintOut method carries out the PrintOut action in Visual Basic.

Quit - The Quit method quits Microsoft Access. You can select one of several options for saving a database object before quitting.

RefreshRecord - The RefreshRecord method performs the RefreshRecord macro operation from Visual Basic.

Rename - The Rename method carries out the Rename action in Visual Basic.

RepaintObject - The RepaintObject method carries out the RepaintObject action in Visual Basic.

Requery - Carries out the Requery action in Visual Basic.

Restore - The Restore method carries out the Restore action in Visual Basic.

RunCommand - The RunCommand method runs a built-in command.

RunDataMacro - Use the RunDataMacro method to run a named data macro from Visual Basic.

RunMacro - The RunMacro method carries out the RunMacro action in Visual Basic.

RunSavedImportExport - Run a saved import or export specification.

RunSQL - The RunSQL method carries out the RunSQL action in Visual Basic.

Save - The Save method carries out the Save action in Visual Basic.

SearchForRecord - You can use the SearchForRecord method to search for a specific record in a table, query, form, or report.

SelectObject - The SelectObject method carries out the SelectObject action in Visual Basic.

SendObject - The SendObject method carries out the SendObject action in Visual Basic.

SetDisplayedCategories - Specifies which categories are displayed under Navigate to Category in the title bar of the navigation pane.

SetFilter - Use the SetFilter method to apply a filter to the records in the active datasheet, form, report, or table.

SetMenuItem - The SetMenuItem method carries out the SetMenuItem action in Visual Basic.

SetOrderBy - Use the SetOrderBy method to apply a sort to the active datasheet, form, report, or table.

SetParameter - Use the SetParameter method to create a parameter for use by the BrowseTo, OpenForm, OpenQuery, OpenReport, or RunDataMacro methods.

SetProperty - The SetProperty method carries out the SetProperty action in Visual Basic.

SetWarnings - The SetWarnings method carries out the SetWarnings action in Visual Basic.

ShowAllRecords - The ShowAllRecords method carries out the ShowAllRecords action in Visual Basic.

ShowToolbar - The ShowToolbar method carries out the ShowToolbar action in Visual Basic.

SingleStep - Pauses macro execution and opens the Macro Single Step dialog box.

TransferSharePointList - You can use the TransferSharePointList method to import or link data from a SharePoint Foundation site.