Results 1 to 3 of 3
  1. #1
    tmartin is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2015
    Posts
    37

    Error Adding custom menu Invalid procedure call or argument

    I placed the createNewMenu code in the onload event of the report. The first time it runs then the menu is added and works fine. If I call the report again and try to
    reload the createNewMenu, I get a Run-Time error '5' Invalid procedure call or argument. I added a MsgBox to the Report_Load (not shown) and if I choose not to run
    the createNewMenu after the 1st time then it works fine. Where should I put the createNewMenu code and appears it should only be executed once.

    Private Sub Report_Load()
    Call createNewMenu
    End Sub
    Public Sub createNewMenu()
    Dim cmbRightClick As Office.CommandBar
    Dim cmbControl As Office.CommandBarControl

    ' Create the shortcut menu.
    Set cmbRightClick = CommandBars.Add("cmdReportRightClick", msoBarPopup, False, True)

    With cmbRightClick

    ' Add the Print command.
    Set cmbControl = .Controls.Add(msoControlButton, 2521, , , True)
    ' Change the caption displayed for the control.
    cmbControl.Caption = "Quick Print"

    ' Add the Print command.
    Set cmbControl = .Controls.Add(msoControlButton, 15948, , , True)
    ' Change the caption displayed for the control

    ' Add the Page Setup... command.
    Set cmbControl = .Controls.Add(msoControlButton, 247, , , True)
    ' Change the caption displayed for the control.


    cmbControl.Caption = "Page Setup"

    cmbControl.BeginGroup = True

    ' Add the PDF or XPS command.
    Set cmbControl = .Controls.Add(msoControlButton, 12499, , , True)
    ' Change the caption displayed for the control.
    cmbControl.Caption = "Save as PDF/XPS"

    cmbControl.BeginGroup = True

    Set cmbControl = .Controls.Add(msoControlButton, 106, , , True)
    ' Change the caption displayed for the control.
    cmbControl.Caption = "Close Report"
    End With

    Set cmbControl = Nothing
    Set cmbRightClick = Nothing
    End Sub

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I use another approach, than VBA, to create shortcut menus. Although, I have been meaning to get around to doing it with VBA.

    My experience is custom Shortcuts have names and are stored with the Access DB file. Once they are created, you can use a form's or report's properties to associate your Custom Shortcut to the form/report. You cannot create two menus with the same name. You can import and export custom shortcut menus using the advanced options in the Import Wizard.

    I would run the code once, from a hidden form or the immediate window. Once it is created, associate the shortcut via the properties of the desired Report/Form.

  3. #3
    tmartin is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2015
    Posts
    37
    I added this to the report and then copied vbaShortCutMenu to the Property Sheet under Shortcut Menu bar
    Everything seems to work fine now. The contents are slightly different that was posted earlier. I have attached just in case someone else
    might be interested.




    Option Compare Database

    Private Sub Report_Load()
    Call CreateReportShortcutMenu
    End Sub

    Private Sub CreateReportShortcutMenu()
    Dim cmbRightClick As Office.CommandBar
    Dim cmbControl As Office.CommandBarControl
    Dim MenuName As String

    MenuName = "vbaShortCutMenu"

    On Error Resume Next

    Application.CommandBars(MenuName).Delete


    ' Create the shortcut menu.
    Set cmbRightClick = Application.CommandBars.Add(MenuName, msoBarPopup, False, False)

    With cmbRightClick

    ' Add the Print command.
    Set cmbControl = .Controls.Add(msoControlButton, 2521, , , True)
    ' Change the caption displayed for the control.
    cmbControl.Caption = "Quick Print"

    ' Add the Print command.
    Set cmbControl = .Controls.Add(msoControlButton, 15948, , , True)
    ' Change the caption displayed for the control

    ' Add the Page Setup... command.
    Set cmbControl = .Controls.Add(msoControlButton, 247, , , True)
    ' Change the caption displayed for the control.
    cmbControl.Caption = "Page Setup"

    cmbControl.BeginGroup = True

    ' Add the PDF or XPS command.
    Set cmbControl = .Controls.Add(msoControlButton, 12499, , , True)
    ' Change the caption displayed for the control.
    cmbControl.Caption = "Save as PDF/XPS"

    cmbControl.BeginGroup = True

    Set cmbControl = .Controls.Add(msoControlButton, 106, , , True)
    ' Change the caption displayed for the control.
    cmbControl.Caption = "Close Report"
    End With

    Set cmbControl = Nothing
    Set cmbRightClick = Nothing
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Invalid Procedure Call error - MS Access
    By Saleem13 in forum Access
    Replies: 5
    Last Post: 10-23-2013, 11:36 AM
  2. Replies: 9
    Last Post: 12-08-2012, 04:56 PM
  3. Invalid Procedure Call or Argument
    By Trojnfn in forum Access
    Replies: 2
    Last Post: 10-29-2012, 01:44 PM
  4. Replies: 9
    Last Post: 08-10-2012, 03:10 AM
  5. invalid procedure call
    By johnmerlino in forum Access
    Replies: 5
    Last Post: 12-13-2010, 10:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums