?
Solved

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

Posted on 2018-01-12
6
Medium Priority
?
38 Views
Last Modified: 2018-01-17
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
0
Comment
Question by:Clive Beaton
  • 3
  • 2
6 Comments
 
LVL 38

Expert Comment

by:ste5an
ID: 42433257
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
 

Author Comment

by:Clive Beaton
ID: 42433272
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
 
LVL 38

Expert Comment

by:ste5an
ID: 42433278
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
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 

Author Comment

by:Clive Beaton
ID: 42433287
Thanks.  I did that and it was called.  I also stepped through the code and there were no errors.
0
 
LVL 50

Accepted Solution

by:
Dale Fye earned 2000 total points
ID: 42433699
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
 

Author Closing Comment

by:Clive Beaton
ID: 42438111
Thanks, Dale.  Very Useful.  I will certainly read your articles.

CRB
0

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

A quick solution showing how to control and open a POS Cash Register Drawer using VBA with MS Access.
This article presents several of my favorite code snippets.
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

568 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question