ACC97: DoMenuItem Method Fails in a Modal Pop-up Form

Last reviewed: March 13, 1998
Article ID: Q182435
The information in this article applies to:
  • Microsoft Access 97

SYMPTOMS

Moderate: Requires basic macro, coding, and interoperability skills.

When you use the DoMenuItem method in a form whose PopUp and Modal properties are set to Yes, the action called by the DoMenuItem method may fail silently or return the following error message:

   The command or action <action> isn't available now.

NOTE: Some actions called by the DoMenuItem method also fail if you set the PopUp property of a form to Yes, regardless of whether or not the Modal Property is set to Yes.

This problem can occur when you use the Command Button Wizard to create a button on a pop-up form, because the wizard generates a Visual Basic for Applications procedure that uses the DoMenuItem method.

RESOLUTION

If you need to set the Modal and PopUp properties of a form to Yes, you can replace the DoMenuItem method with the equivalent RunCommand method. However, some DoMenuItem action commands do not have equivalent RunCommand actions. For more information, search the Help Index for "DoMenuItem action" and display the topic "DoMenuItem Action Commands Not Available with the RunCommand Action."

The following steps demonstrate how to change actions of the DoMenuItem method to the corresponding actions of the RunCommand method:

  1. Follow steps 1 - 12 in the "Steps to Reproduce Problem" section later
     in this article.

  2. Open the frmDoMenuTest form in Design View.

  3. Right-click the Delete Record button; then click Build Event on the
     shortcut menu. Note the Visual Basic for Applications code created by
     the Command Bar wizard:

       Private Sub Command10_Click()
          On Error GoTo Err_Command10_Click

           DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
           DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

       Exit_Command10_Click:
          Exit Sub

       Err_Command10_Click:
         MsgBox Err.Description
         Resume Exit_Command10_Click

      End Sub

  4. Type an apostrophe (') at the beginning of the following lines:

       DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
       DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

     This changes the lines of code so that they become comments, which
     are not executed.

  5. Immediately after the lines that you changed to comments in step 4,
     type the following lines:

       DoCmd.RunCommand acCmdSelectRecord
       DoCmd.RunCommand acCmdDeleteRecord

  6. Close the Module window and save the form.

  7. On the View menu, click Form View.

  8. Click the Delete Record button. Note that you are prompted to confirm
     that you want to delete the record.

STATUS

Microsoft has confirmed this to be a problem in Microsoft Access 97. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

The Visual Basic for Applications code generated by the Command Button wizard often uses the DoMenuItem method.

Steps to Reproduce Problem

  1. Start Microsoft Access 97 and open the sample database Northwind.mdb.

  2. In the Database window, click the Tables tab, and select the Order
     Details table.

  3. On the Insert menu, click AutoForm. Save the form as frmDoMenuTest.

  4. On the View menu, click Design View.

  5. If the toolbox is not already visible, click Toolbox on the View menu.

  6. Make sure that the Control Wizard button is pressed in; the button
     face of the Control Wizard button is a picture of a wand.

  7. Click the command button tool in the toolbox and add a command button
     to the detail section of the form.

  8. On the first screen of the Command Button Wizard, select Record
     Operations in the Categories list and Delete Record in the Actions
     list. Click Finish.

  9. On the Edit menu, click Select Form.

 10. On the View menu, click Properties, and then click the Other tab. Set
     the PopUp property and the Modal property of the form to Yes.

 11. Save and close the frmDoMenuTest form.

 12. Open the frmDoMenuTest form in Form view and click the Delete Record
     button. Note that the action fails silently and the current record is
     not deleted.

REFERENCES

For more information about converting DoMenuItem actions to RunCommand actions, search the Help Index for "DoMenuItem method."


Additional query words: pra
Keywords : FmsButb MdlAdrec WzProb
Version : WINDOWS:97
Platform : WINDOWS
Hardware : x86
Issue type : kbbug
Solution Type : kbpending


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 13, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.