Macro Actions and Methods of the DoCmd Object

Microsoft Access Visual Basic

Show All

Macro Actions and Methods of the DoCmd Object

   

To carry out macro actions from code in Microsoft Access, use the DoCmd object and its methods. This object replaces the DoCmd statement that you used in versions 1.x and 2.0 of Microsoft Access to carry out a macro action.

When you convert a database, Microsoft Access automatically converts any DoCmd statements and the actions that they carried out in your Access Basic code to methods of the DoCmd object by replacing the space with the . (dot) operator.

Some macro actions work differently in Microsoft Access 9.0 and later than in version 1.x, 2.0, or 7.0; these differences are detailed below.

Databases Created with Microsoft Access 95

The DoMenuItem Action

The DoMenuItem action is no longer used in Microsoft Access. The RunCommand action can be used to accomplish the tasks for which you used to use the DoMenuItem action.

When you enable a database created with a prior version of Microsoft Access, the DoMenuItem action will continue to work as it did before.

When you convert a database created with a prior version of Microsoft Access, all DoMenuItem actions in macros are replaced with RunCommand actions the first time that the macros are saved after conversion. DoMenuItem methods used in Visual Basic procedures aren't changed.

Databases Created with Microsoft Access Version 1.x or 2.0

The TransferSpreadsheet Action

Microsoft Access can't import Microsoft Excel version 2.0 spreadsheets or Lotus 1-2-3 version 1.0 spreadsheets. If your converted database contains a macro that provided this functionality by using the TransferSpreadsheet action in Microsoft Access version 1.x or 2.0, converting the database will change the Spreadsheet Type argument to Microsoft Excel version 3.0 (if you originally specified Microsoft Excel version 2.0), or causes an error if you originally specified Lotus 1-2-3 version 1.0 format.

To work around this problem, convert the spreadsheets to a later version of Microsoft Excel or Lotus 1-2-3 before importing them into Microsoft Access.

The TransferText and TransferSpreadsheet Actions

In Microsoft Access, you can't use a SQL statement to specify data to export when you're using the TransferText action or the TransferSpreadsheet action. Instead of using a SQL statement, you must first create a query and then specify the name of the query in the Table Name argument.

Comparisons Involving Null Values

In Microsoft Access versions 1.x and 2.0, if you compare two expressions within a macro condition by using a comparison operator and one of the expressions is Null, Access Basic will return True or False for the comparison, depending on which comparison operator you use. In Microsoft Access 2000 and later, Visual Basic returns Null for a comparison in which one expression is Null. To determine whether the comparison evaluates to Null, use the IsNull function to check the result of the comparison.