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

Clive BeatonAccess DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
Clive BeatonAccess DeveloperAuthor 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"
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.
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Clive BeatonAccess DeveloperAuthor Commented:
Thanks.  I did that and it was called.  I also stepped through the code and there were no errors.
Dale FyeCommented:
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:
Part 2:
Part 3:
Part 4:

or tried out the Access Shortcut Tool?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Clive BeatonAccess DeveloperAuthor Commented:
Thanks, Dale.  Very Useful.  I will certainly read your articles.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.