Known Problems With RunCommand

If you know of any other problems when using RunCommand then please let me know so that I can add details to this page.

acCmdImport not supported in Access 2007
acCmdSizeToFitForm Limitations
acCmdSynchronizeNow Hangs
Cannot Save Position of Form Using acCmdSave in Code
Cannot Use acCmdSaveModuleAsText in Code
Code Will Not Run On Form Or Report Events
Command Button Wizard does not use RunCommand
Command is not available now
Convert Macros to Visual Basic Converts Incorrectly
DoMenuItem - No Equivalent
How can you use an Access 2007 constant (e.g.acCmdImportAttachAccess) in Access 2003
DoMenuItem not converted
Modal and PopUp Form Does Not Support RunCommand
No RunCommand Equivalent to a Menu Item
RunCommand Constants Truncated
RunCommands That Force a Dialog Box
Runtime - Server Filter By Form in Access 2002
Runtime - Filter By Form
Runtime - Missing Menu Items
Runtime - RunCommand action cancelled
SourceSafe Commands not available for RunCommand method
Timer Event causes problem with RunComand

Cannot Save Position of Form Using acCmdSave in Code

Problem

In ver2 I had the following lines for saving the form position: (in Form_Unload)

DoCmd.DoMenuItem A_FORMBAR, A_FILE, A_SAVEFORM, , A_MENU_VER20

This doesn't seem to work properly, so I changed it to:

DoCmd.DoMenuItem acFormBar, acFile, acSaveForm, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acFile, acSave, , acMenuVer70

Neither of these last commands seems to do what I could do in ver2. When I hit the save icon on the toolbar I get the desired result. Can someone direct me to what DoMenuItem command I should use, so the users have their forms automatically saved to the position it had when they closed the form.

Solution

Access 97 seems to have changed when the position of the form is saved. Place the following code in the On_Resize event.

DoCmd.RunCommand acCmdSave

Note: This code will not work if AutoCentre is set to yes.

Return to Top of Page

DoMenuItem not converted

DoCmd DoMenuItem in version 2 code or DoCmd.DoMenuItem in version 7.0 code is not automatically converted to the Microsoft Access 97 RunCommand syntax, but the DoMenuItem syntax works correctly in Microsoft Access 97.

DoMenuItem macro actions are automatically converted to their equivalent RunCommand actions when you open a macro in the Macro window.

Return to Top of Page

RunCommand Constants Truncated After 25 Characters

There is a 25 character limitation for the RunCommand constants when using the "Convert Macro to Visual Basic" command. The affected RunCommands are:-

For more information and a solution see PSS ID Number: Q168311 on the Microsoft site.

Return to Top of Page

Filter By Form Error In Runtime

When you try to open a form in Filter-by-Form view programmatically in a Microsoft Access 97 run-time application, you may receive the following error message
Run-time error '2501':
The RunCommand action was canceled.

followed by:
Execution of this application has stopped due to a run-time error. The application can't continue and will be shut down.

For more information on this problem see PSS ID Number: Q172090 ODE97 on the Microsoft site.

Possible Solution

For a possible solution see PSS ID Number: Q166634 on the Microsoft site.

Return to Top of Page

Error Using RunCommand Method in Runtime

When you use the RunCommand method in a Microsoft Access 97 run-time application, you may receive the following error message:

The RunCommand action was canceled.

This occurs when using a method that prompts the user for an input or output file name. The following constants of the RunCommand method will cause this problem:

For more information on this problem see PSS ID Number: Q173334 on the Microsoft site.

Return to Top of Page

Command Button Wizard does not use RunCommand

The Command Button Wizard still generates code using DoMenutItem rather than using the RunCommand method of the DoCmd object.

Return to Top of Page

SourceSafe Commands not available for RunCommand method

The RunCommand method does not expose the menu commands to control Visual SourceSafe Integration from either Visual Basic for Applications code or macros.

For more information on this problem see PSS ID Number: Q162931 on the Microsoft site.

Return to Top of Page

Missing Menu Items in Runtime Environment

When you build a custom menu bar in Microsoft Access 97 and include the built-in File menu, some commands do not appear on the menu in the run-time environment. For example, the Print command does not appear on the menu; as a result, you cannot modify the printer settings or properties. You can create a Microsoft Visual Basic for Applications function that displays the Print dialog box and attach that function to a custom Menu Bar.

For more information see PSS ID Number: Q173796 on the Microsoft Knowledge Base.

Return to Top of Page

Modal and PopUp Form Does Not Support RunCommand

Code containing RunCommand does not run correctly on a form which opens Modal and PopUp. An example of the constants that do not work are acCmdPaste and acCmdPasteAppend. This would appear to be because these commands would not normally be available from the menu at this time.

A work around is to set the Modal property to Yes but the PopUp property to No. The RunCommand constants should now work correctly.

Return to Top of Page

Code Will Not Run On Form Or Report Events

Certain RunCommand constants cannot be run from code started by an event on a form or a report. The only way to use them is to create functions which are run from custom menu items. Constants which I know to have problems follow. I will add to this list as I find out more.

Return to Top of Page

Cannot Use acCmdSaveModuleAsText in Code

Problem

In both Access 97 and Access 2000, when you run code that contains the RunCommand method with the acCmdSaveModuleAsText constant, you may receive the following error message:

The command or action 'SaveModuleAsText' isn't available now.

Cause

Microsoft Access cannot save a code module while code is running.

Solution

Use the OutputTo method of DoCmd.

For more information on this problem see PSS ID Number: Q161087 for Access 97 or PSS ID Number: Q200646 for Access 2000 on the Microsoft site.

Return to Top of Page

Convert Macros to Visual Basic Converts Incorrectly

The following macro RunCommand actions do not correctly convert to acCmd constants when the Convert Macros to Visual Basic command is run.

The converted code gives a Variable Not Defined error. For more information on this problem see PSS ID Number: Q167061 on the Microsoft site.

Return to Top of Page

acCmdSizeToFitForm Limitations

The RunCommand acCmdSizeToFitForm will produce errors when used in a form's OnOpen Event but it seems to run fine if used in the form's OnActivate Event. Thanks to Kate McDonald for this information.

It would appear to work properly in the Load event as well. Thanks to Kris Van Dijck for this information.

Return to Top of Page

DoMenuItem - No Equivalent RunCommand

When you convert a Microsoft Access database from a previous version of Microsoft Access, some commands may no longer be available. A command may have been renamed, moved to a different menu, or may no longer be available in Microsoft Access 97. The DoMenuItem actions for such commands can't be converted to RunCommand actions. See Help "DoMenuItem Action Commands Not Available with the RunCommand Action".

Return to Top of Page

No RunCommand Equivalent to a Menu Item

In Access 2000, there appears to be no RunCommand equivalent to File, Export. The following code from Dev Ashish works but cannot be guaranteed for future versions of Access.

' ********* Code Start ***********
Sub sExportDialog()
  If Application.CurrentObjectType = acTable Then
    CommandBars("File").Controls(7).Execute
  End If
End Sub
' ********* Code End ************

Thanks to Manish Jha for this information.

Return to Top of Page

Timer Event causes problem with RunCommand

Timer Events on forms have been reported to interfer with code which contains RunCommand. I have heard of the following involving acCmdSaveRecord, acCmdPrint, acCmdDatasheetView and acCmdFormView.

acCmdDatasheetView and acCmdFormView

The following information was given to me by Michel Jasmin.


The commands acCmdDatasheetView and acCmdFormView seems to be affected by the timer event like acCmdSaveRecord. With a timer of 60 seconds the command fails sometimes (1 on 4, 1 on 5, hard to pin point).

Instead of using the timer event I'm using a VB DLL, the code source for which is avaliable somewhere on MSDN as a VB sample program. The project is named xtimers.vbp and is a part of a "coffee machine" application.


acCmdSaveRecord

The following information was posted by Andrew Flowers to the comp.databases.ms-access newsgroup.


We have narrowed down the cause of our problem to a timer event on our main form.

We use a timer that fires every 30 seconds (TimerInterval=30000) to record a watchdog event which basically says the application is still alive. The command fails intermitently

If we set the TimerInterval to 500 we get our save failing constantly.

If we set the body of the event to nothing and TimerInterval to 500 we get our save failing constantly.

If we set the TimerInterval to 0 we get no save fails.


acCmdPrint

The following information was given to me by Tom Gunderson of Gunderson Software Inc.


I ran into a strange problem using the acCmdPrint constant of RunCommand to get the dialog box. I referenced the standard code from the MS KB article (173796) from a button on a custom print preview toolbar. The problem was that the first time clicking the print button would bring up the dialog and print a report just fine, the second time, it would bring up the dialog and print my "Main Menu" form (a non-modal, non-popup form that was just sitting in the background). Now, this form did NOT have focus at all, but the acCmdPrint printed it out.

After searching, testing, etc. I noticed I had a timer event in the "Main menu" form, which was firing every 10 seconds (updating a time field on the form with the current system time). Removing the timer event resolved the problem. So apparently the timer event gave some sort of internal 'focus' to that form, which caused acCmdPrint to print that, rather than the report which was the current active object.


Return to Top of Page

ServerFilterByForm Property in Access 2002

In order to enabler the Server Filter By Form in an Access 2002 Run Time Application can cause problems. If you only use DoCmd.RunCommand acCmdServerFilterByForm and do not set the property first, you will receive one of the following error messages:

In the retail version of Access:

Run-time error '2046':The command or action 'ServerFilterByForm' isn't available now.

In a run-time application:

Execution of this application has stopped due to a run-time error. The application can't continue and will be shut down.

For more information on this problem see the Microsoft Knowledge Article Q283362.

Return to Top of Page

RunCommands That Force a Dialog Box

Using the following RunCommands results in a dialog box prompting for a file name.

Return to Top of Page

acCmdSynchronizeNow Hangs

There is a known problem that if you use acCmdSynchronizeNow to synchronise in code or a macro. It is possibe that the system will hang. The work around is to write the actual code to synchronize.

Thanks to JoAnn Ross for this information

Return to Top of Page

acCmdImport not supported in Access 2007

Microsoft Technet reports that DoCmd.RunCommand acCmdImport and the Import RunCommand macro are no longer supported. Making this object model call or macro RunCommand call will result in an error message. This has been replaced by more specific ImportAttach… commands.

Return to Top of Page

How can you use an Access 2007 constant (e.g.acCmdImportAttachAccess) in Access 2003.

This question was raised by Nicole Gestels from Belguim. Nicole was trying to run the following code:-

If Val(Application.Version) <= 11 Then
  DoCmd.RunCommand acCmdLinkTables
Else
  DoCmd.RunCommand acCmdImportAttachAccess
End If

This gives an error in Access 2003 (unknown variable acCmdImportAttachAccess).

The answer is to replace the RunCommand variables with their numberical equivalents as follows:

If Val(Application.Version) <= 11 Then
  DoCmd.RunCommand 102 ' the value of acCmdLinkTables
Else
  DoCmd.RunCommand 544 ' the value of acCmdImportAttachTables
End If

Return to Top of Page

© 1998 - 2011 Terry Wickenden TKW Design Site developed, maintained and hosted by TKW Design. This site is best viewed at 1024 x 768. Optimised for Firefox.