Is there a way to test, in VBA, if the Shortcut menus have been created

I had this question after viewing Problem with Shortcut Menus.

In the original question, Dale Fye asked: "Are you actually rerunning that code to recreate the menu each time you load your application?  If so, why?  Once you create that menu as a permanent menu, you should not need to mess with it again."

Answer: I have to run it because I don't know if this is an initial installation and therefore not run before.

So, Is there a way to test, in VBA, if the Shortcut menus have been created?

Thanks in advance

CRB
CRB1609Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Dale FyeConnect With a Mentor Commented:
This is the function I use to tell if the commandbar exists, but given that you are using passing TRUE as the 4th (Temporary) argument of the Add method, when you create the commandbar, and also with the Controls.Add method, all of the commandbars you create this way are temporary, and are only valid for the Access session.  
CommandBars.Add("StandardReports", msoBarPopup, False, True)
Set cmbControl = .Controls.Add(msoControlButton, 923, , , True)

Open in new window

If you replace those values with False, then you only need to create the commandbar once, and it will always exist within your appication, until you delete it.

Here is the function I use to determine whether a commandbar exists or not.
Public Function CmdBarExists(BarName As String)

    Dim intCount As Integer

    On Error Resume Next
    intCount = CommandBars(BarName).Controls.Count
    CmdBarExists = (Err.Number = 0)
    On Error GoTo 0

End Function

Open in new window


Have you looked at my articles on commandbars
Part 1: https://www.experts-exchange.com/articles/11333/Understanding-and-using-CommandBars-ShortCut-menus-Part-1.html
Part 2: https://www.experts-exchange.com/articles/12904/Understanding-and-using-CommandBars-Part-II-Creating-your-own.html
Part 3: https://www.experts-exchange.com/articles/18341/CommandBars-Part-III-Using-Built-in-Shortcut-Menus.html
Part 4: https://www.experts-exchange.com/articles/24219/Using-Shortcut-right-click-menus-in-the-Access-runtime-environment.html

or tried out the Access Shortcut Tool?
0
 
ste5anSenior DeveloperCommented:
This should not be another question.. cause Dale is right. Is your method really called?

To ensure this add some logging to your method. At least a Debug.Print to check in the failing case, whether it was called or not.

Caveat: Depending on how you call it, also a Resume Next in the calling methods may hide any error with it.
0
 
CRB1609Author Commented:
I don't use a method (function).  I use the standard msoControlButton to close. ie:

      Set cmbControl = .Controls.Add(msoControlButton, 923, , , True)
      cmbControl.BeginGroup = True
      cmbControl.Caption = "Close Report"
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
ste5anSenior DeveloperCommented:
Add a Debug.Print to your method:

Sub CreateStandardReportsShortcutMenu
  Debug.Print "Entered CreateStandardReportsShortcutMenu.."
  ' your code
End Sub

Open in new window

And check the immediate window in the VBA IDE whether it was called.
0
 
CRB1609Author Commented:
Thanks.  I did that and it was called.  I also stepped through the code and there were no errors.
0
 
CRB1609Author Commented:
Thanks, Dale.  Very Useful.  I will certainly read your articles.

CRB
0
All Courses

From novice to tech pro — start learning today.