Docmd Access Visual Basic

The Access VBA Docmd object allows you to run a macro command within a visual basic module.This method is preferred over actually creating macros in your database. The command is used in all of our databases – you can see examples of Inventory, Reservation and Orders databases in our case studies.Many of the action methods of the DoCmd object have parameters or arguments.  Many of the arguments are required and others are optional.  If you do not define one of the optional arguments the value of the argument will revert to its default value.

The DoCmd object does not work for the following macro actions:

  • AddMenu

  • MsgBox – Replaces by MsgBox function

  • RunApp – Use the Shell function instead to run another application

  • RunCode – Run the function directly in Access Visual Basic

  • SendKeys – Use the SendKeys command

  • SetValue – Assign values directly in VBA

  • StopAllMacros

  • StopMacro

The following list of DoCmd methods shows the commonly used commands.  The general format for the command is Docmd.Action. There are often one or more options to these action methods. The method examples & definitions on the coding example pages are paraphrased from Access help for clarity and additional code examples have been added.

Example Page Example Description DoCmd Add Menu The AddMenu command example demonstrates how to add an item to customized dropdown menus at the top of the Microsoft Access database screen. DoCmd Apply Filter These examples employ the Docmd.ApplyFilter method to display only records that contain the state MD in the State field. DoCmd Cancel Event The Cancel Event method quits the event that caused Microsoft Access to run the code containing this action.  All further execution of the event is aborted. DoCmd Close The Access Close method carries out the Close action in Visual Basic to close a form, report, or query in the running database. DoCmd Copy Object Docmd.CopyObject allows you to duplicate any database object. DoCmd Delete Object The DoCmd DeleteObject method performs a delete operation on Access’s objects such as tables, queries, forms and reports. DoCmd Find Record The Access DoCmd.FindRecord method performs the Find Record action in Visual Basic.  This command is often used in conjunction with the Docmd.FindNext to automate searching for datasheet records based on user input. DoCmd Find Next Find the next record that meets the criteria specified by the previous FindRecord action or the Find In Field dialog box. DoCmd Goto Control Move the focus to the indicated field or control in the current record of the open form, datasheet, table datasheet, or query datasheet. DoCmd Hour Glass Change the mouse pointer to an hourglass icon (or another icon of your choice) while program is running. This method is used when running a procedure from VBA that takes a while to run. DoCmd Minimize Minimize docmd shrinks the active window down to the smallest size available while still showing the forms close and min/max size icons. DoCmd Maximize The maximize command changes the size of the active Access form to the maximum dimensions allowed by the active Access application. DoCmd Restore Docmd Restore returns the size of the active form to the setting previous to a maximize or minimize docmd execution. DoCmd Open Form Open in Form view, datasheet, print preview, or design view DoCmd Open Query Open a select or crosstab query in design, datasheet, or print preview. Or, execute an action query from VBA script DoCmd Open Report Open a report in design or print preview, or to print the report directly to the default printer. DoCmd Output To Output data in the current database (a datasheet, form, report, module, DAP) to a file in Excel, DOS text (*.txt), or rich-text format. DoCmd Run SQL Run an SQL action query by using the SQL command. You may also run aDDL query DoCmd Send Object Include the specified datasheet, form, report, module, or data access page in an e-mail message – there it can be viewed and sent. DoCmd Transfer Text The TransferText method sends/receives records from/to the database or project and a file on your hard drive. The transfertext method may also be employed to establish data table links between databases. TransferDatabase Import or export data from/to the current database (.mdb) or project (.adp) and other databases such as FoxPro, dBase, and ODBC databases.

>>>>>NEW LINKS WILL BE HERE AFTER PAGES COMPLETED<<<<<< Open Email Using SendObject Access Download User Inactivity Logout VBA Code Disable Shift Key Demo Send Email Microsoft Access Tutorial Download (Advanced) Sequential Counter in Query Multi Select List Box Query Parameters Row Level Data Security Programming MS AccessSecurity Alternative Single User Inventory Calculations Download How To PerformMulti-User Inventory Calculations Make Dependent Combo Box Code MS Access Tutorial Union Query Example (Simple) Union Query (Advanced) Access Tutorial How ToFill Fields From Combo Box Use Global Variables as Parameters Continuous Form Dependent Combo Box How To Program Continuous-Continuous Master/Detail Forms Access Bar Chart / Bar Graph Programming Crosstab Query Example TransferText & OutputTo Microsoft Access DoCmd.OpenForm & OpenArgs VBA Example Running Sum Query Method Choose Command Dynamic SQL Order By Access Conditional Format Access Report Banding

Popup Form Control Method

Microsoft Office VBA, MS Access 2003, 2007, 2010, 2013, 2016