DoCmd object (Access)
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.
Remarks
For example, you can use the OpenForm method of the DoCmd object to open a form, or use the Hourglass method to change the mouse pointer to an hourglass icon.
Most of the methods of the DoCmd object have arguments; some are required, while others are optional. If you omit optional arguments, the arguments assume the default values for the particular method. For example, the OpenForm method uses seven arguments, but only the first argument, FormName, is required.
The following example shows how you can open the Employees form in the current database. Only employees with the title Sales Representative are included.
DoCmd.OpenForm "Employees", , ,"[Title] = 'Sales Representative'"
The DoCmd object doesn't support methods corresponding to the following actions:
- MsgBox. Use the MsgBox function.
- RunApp. Use the Shell function to run another application.
- RunCode. Run the function directly in Visual Basic.
- SendKeys. Use the SendKeys statement.
- SetValue. Set the value directly in Visual Basic.
- StopAllMacros.
- StopMacro.
Example
The following example opens a form in Form view and moves to a new record.
Sub ShowNewRecord()
DoCmd.OpenForm "Employees", acNormal
DoCmd.GoToRecord , , acNewRec
End Sub
Methods
- AddMenu
- ApplyFilter
- Beep
- BrowseTo
- CancelEvent
- ClearMacroError
- Close
- CloseDatabase
- CopyDatabaseFile
- CopyObject
- DeleteObject
- DoMenuItem
- Echo
- FindNext
- FindRecord
- GoToControl
- GoToPage
- GoToRecord
- Hourglass
- LockNavigationPane
- Maximize
- Minimize
- MoveSize
- NavigateTo
- OpenDataAccessPage
- OpenDiagram
- OpenForm
- OpenFunction
- OpenModule
- OpenQuery
- OpenReport
- OpenStoredProcedure
- OpenTable
- OpenView
- OutputTo
- PrintOut
- Quit
- RefreshRecord
- Rename
- RepaintObject
- Requery
- Restore
- RunCommand
- RunDataMacro
- RunMacro
- RunSavedImportExport
- RunSQL
- Save
- SearchForRecord
- SelectObject
- SendObject
- SetDisplayedCategories
- SetFilter
- SetMenuItem
- SetOrderBy
- SetParameter
- SetProperty
- SetWarnings
- ShowAllRecords
- ShowToolbar
- SingleStep
- TransferDatabase
- TransferSharePointList
- TransferSpreadsheet
- TransferSQLDatabase
- TransferText
See also
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기