Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Access 2007 - using shortcut / right click command bars

Posted on 2007-11-19
5
3,191 Views
Last Modified: 2013-11-28
I have used shortcut menus fine in access 2003 where it allows you to set these up manually. From looking through the posts it looks like you can add these in code and looks like you only need to run code once to set up.

However I can't find the right code to set up - looks like it relates to CommandBars.Add and then adding controls to this but I cannot get right code without an error.

Does anyone have the code to set up a shortcut menu which I can then select in the shortcut menu bar Property on a control on a form.

I would like to set up a shortcut with say 3 items to select - Ideally I would like one of these to run a function.
0
Comment
Question by:donhannam
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:MrXmas
ID: 20317504
donhannam,

Here's some code that I've been using.  

My toolbar is called "Novitas Tools"  (it's the name of a large application I wrote).  The code first removes the toolbar if it's there, then adds the buttons one by one.  Change the lines NewBtn.OnAction =  to reference your subroutine name.

Hope this is what you were looking for.

--Jim Christmas
Sub NovitasToolbar()
 
Dim ctlPop As CommandBarPopup
Dim ctl As CommandBarControl
Dim NewBtn As CommandBarButton
Dim strPlatform As String
 
    On Error GoTo Exit_Toolbars
 
    'Remove Existing
 
    For Each ctl In Application.CommandBars("Menu Bar").Controls
        If ctl.Caption = "Novitas Tools" Then ctl.Delete
    Next ctl
 
    Set ctlPop = Application.CommandBars("Menu Bar").Controls.Add(msoControlPopup, , , , True)
    ctlPop.Caption = "Novitas Tools"
        
    Set NewBtn = ctlPop.Controls.Add(msoControlButton)
    NewBtn.Caption = "Lookup a Novitas &User"
    NewBtn.OnAction = "LaunchWhoIs"
    NewBtn.FaceId = 362
    
    Set NewBtn = ctlPop.Controls.Add(msoControlButton)
    NewBtn.Caption = "&Calculator"
    NewBtn.OnAction = "LaunchCalc"
    NewBtn.FaceId = 283
    
    Set NewBtn = ctlPop.Controls.Add(msoControlButton)
    NewBtn.Caption = "Calen&dar"
    NewBtn.OnAction = "LaunchCalendar"
    NewBtn.FaceId = 1106
    
    Set NewBtn = ctlPop.Controls.Add(msoControlButton)
    NewBtn.Caption = "Send &eMail"
    NewBtn.OnAction = "LaunchContextEMail"
    NewBtn.FaceId = 262
    
    If GetLoginID = "JCHRIS1" Then
        Set NewBtn = ctlPop.Controls.Add(msoControlButton)
        NewBtn.Caption = "&Administration Console"
        NewBtn.OnAction = "LaunchAdmin"
        NewBtn.FaceId = 2144
    End If
    
    Exit Sub
Exit_Toolbars:
    If Err Then Err.Clear
    
End Sub

Open in new window

0
 

Author Comment

by:donhannam
ID: 20317691
Jim,

Tried this - ran without errors but cannot get to work as a shortcut menu.

By playing around a bit managed to get to display on shortcut menu bar list dropdown but when right clicked there was nothing in the list.

Is this for shortcuts or is it for toolbars or menu bars?.

Appreciate any help

Thanks

Don.
0
 
LVL 4

Accepted Solution

by:
MrXmas earned 250 total points
ID: 20317710
DonHannam,

Sorry.  That's for menu bars.  I launch everything from the code in the subs.  

--Jim Christmas
0
 

Author Closing Comment

by:donhannam
ID: 31410046
Not what I was looking for but have used part of code for other uses.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

856 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