473,554 Members | 2,834 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to create a custom shortcut menu command

3 New Member
Dear friends,
I am using MS Access 2022 (office 365), I am having trouble with creating shortcut menu command for report. I tried to follow the same thing posted by Beacon (How to create a custom shortcut menu command that identifies the calling form/report?), I used MS Office 16.0 object library as reference. The code causes no error, but when on use right mouse click on the form/report that call the sub creating the custom short cut menu, it shows only the standard shortcut menu of ms access. The code posed as said above is here below. Please help to advise.
Expand|Select|Wrap|Line Numbers
  1. Sub CreateReportShortcutMenu()
  2.  
  3.     Dim cmbReportShortcutMenu As Office.CommandBar
  4.     Dim cmbControl As Office.CommandBarControl
  5.  
  6.     'On Error Resume Next
  7.  
  8.     'Delete the command bar if it already exists
  9.     DeleteContextMenu
  10.  
  11.     ' Create the shortcut menu.
  12.     Set cmbReportShortcutMenu = CommandBars.Add("ReportShortcutMenu", msoBarPopup)
  13.  
  14.     With cmbReportShortcutMenu
  15.  
  16.         ' Add the Print command.
  17.         Set cmbControl = .Controls.Add(msoControlButton, 2521)
  18.         ' Change the caption displayed for the control.
  19.         cmbControl.Caption = "Quick Print"
  20.  
  21.         ' Add the One Page command.
  22.         Set cmbControl = .Controls.Add(msoControlButton, 5)
  23.  
  24.         ' Add the Two Pages command.
  25.         Set cmbControl = .Controls.Add(msoControlButton, 639)
  26.  
  27.         ' Add the Print command.
  28.         Set cmbControl = .Controls.Add(msoControlButton, 15948)
  29.         ' Change the caption displayed for the control.
  30.         cmbControl.Caption = "Select Pages"
  31.  
  32.         ' Add the Page Setup... command.
  33.         Set cmbControl = .Controls.Add(msoControlButton, 247)
  34.         ' Change the caption displayed for the control.
  35.         cmbControl.Caption = "Page Setup"
  36.  
  37.         ' Add the Mail Recipient (as Attachment)... command.
  38.         Set cmbControl = .Controls.Add(msoControlButton, 2188)
  39.         ' Start a new group.
  40.         cmbControl.BeginGroup = True
  41.         ' Change the caption displayed for the control.
  42.         cmbControl.Caption = "Email Report as an Attachment"
  43.  
  44.         ' Add the PDF or XPS command.
  45.         Set cmbControl = .Controls.Add(msoControlButton, 12499)
  46.         ' Change the caption displayed for the control.
  47.         cmbControl.Caption = "Save as PDF/XPS"
  48.  
  49.         ' Add the Close command.
  50.         Set cmbControl = .Controls.Add(msoControlButton, 923)
  51.         ' Start a new group.
  52.         cmbControl.BeginGroup = True
  53.         ' Change the caption displayed for the control.
  54.         cmbControl.Caption = "Close Report"
  55.  
  56.         '*******************************************************
  57.         '* If I was going to use a custom sub/function,
  58.         '* this an example of how I would at least start it
  59.         '*******************************************************
  60.  
  61.         ' Add a blank command
  62.         Set cmbControl = .Controls.Add(msoControlButton, 1)
  63.         cmbControl.Caption = "Email As PDF"
  64.         cmbControl.OnAction = "=MySubFunction()"
  65.  
  66.     End With
  67.  
  68.     Set cmbControl = Nothing
  69.     Set cmbReportShortcutMenu = Nothing
  70.  
  71. End Sub
  72.  
  73. Sub DeleteContextMenu()
  74.  
  75.     On Error Resume Next
  76.     CommandBars("ReportShortcutMenu").Delete
  77.  
  78. End Sub
Mar 8 '23 #1
7 8947
NeoPa
32,564 Recognized Expert Moderator MVP
I won't delete this straight off, in case the reason it's been done so poorly is because of language issues.

However, This is not a valid question. It's a request for someone to do your work for you. You show no signs even of having started to look at what might be going wrong, or even if the code is supposed to do what you want. There is also no clear explanation of exactly what that is. You have code; you have a requirement; clearly these don't match but nor is either explained. What's your requirement? What does the code do that doesn't match that?
Mar 8 '23 #2
bounthong
3 New Member
Hi NeoPa,

It is correct that my English is poor, anyway I will try to be more precise and compact this time.

1. Requirement: I want to have Custom Shortcut Menu for my report.
2. Current situation: I have used the code shown below here in this post (initially posted by Beacon, shown also in my initial post). I have tried by calling this CreateReportSho rtcutMenu (shown below) from by my report, but it does not work. Right mouse click on my report in report preview mode or report view mode, only standard shortcut menu of msaccess appears.

I need help for making the custom shortcut menu worked/appeared.

Hope my English is understandable this time.

Here is the code I use:
Expand|Select|Wrap|Line Numbers
  1. Sub CreateReportShortcutMenu()
  2.  
  3.     Dim cmbReportShortcutMenu As Office.CommandBar
  4.     Dim cmbControl As Office.CommandBarControl
  5.  
  6.     'On Error Resume Next
  7.  
  8.     'Delete the command bar if it already exists
  9.     DeleteContextMenu
  10.  
  11.     ' Create the shortcut menu.
  12.     Set cmbReportShortcutMenu = CommandBars.Add("ReportShortcutMenu", msoBarPopup)
  13.  
  14.     With cmbReportShortcutMenu
  15.  
  16.         ' Add the Print command.
  17.         Set cmbControl = .Controls.Add(msoControlButton, 2521)
  18.         ' Change the caption displayed for the control.
  19.         cmbControl.Caption = "Quick Print"
  20.  
  21.         ' Add the One Page command.
  22.         Set cmbControl = .Controls.Add(msoControlButton, 5)
  23.  
  24.         ' Add the Two Pages command.
  25.         Set cmbControl = .Controls.Add(msoControlButton, 639)
  26.  
  27.         ' Add the Print command.
  28.         Set cmbControl = .Controls.Add(msoControlButton, 15948)
  29.         ' Change the caption displayed for the control.
  30.         cmbControl.Caption = "Select Pages"
  31.  
  32.         ' Add the Page Setup... command.
  33.         Set cmbControl = .Controls.Add(msoControlButton, 247)
  34.         ' Change the caption displayed for the control.
  35.         cmbControl.Caption = "Page Setup"
  36.  
  37.         ' Add the Mail Recipient (as Attachment)... command.
  38.         Set cmbControl = .Controls.Add(msoControlButton, 2188)
  39.         ' Start a new group.
  40.         cmbControl.BeginGroup = True
  41.         ' Change the caption displayed for the control.
  42.         cmbControl.Caption = "Email Report as an Attachment"
  43.  
  44.         ' Add the PDF or XPS command.
  45.         Set cmbControl = .Controls.Add(msoControlButton, 12499)
  46.         ' Change the caption displayed for the control.
  47.         cmbControl.Caption = "Save as PDF/XPS"
  48.  
  49.         ' Add the Close command.
  50.         Set cmbControl = .Controls.Add(msoControlButton, 923)
  51.         ' Start a new group.
  52.         cmbControl.BeginGroup = True
  53.         ' Change the caption displayed for the control.
  54.         cmbControl.Caption = "Close Report"
  55.  
  56.         '*******************************************************
  57.         '* If I was going to use a custom sub/function,
  58.         '* this an example of how I would at least start it
  59.         '*******************************************************
  60.  
  61.         ' Add a blank command
  62.         Set cmbControl = .Controls.Add(msoControlButton, 1)
  63.         cmbControl.Caption = "Email As PDF"
  64.         cmbControl.OnAction = "=MySubFunction()"
  65.  
  66.     End With
  67.  
  68.     Set cmbControl = Nothing
  69.     Set cmbReportShortcutMenu = Nothing
  70.  
  71. End Sub
  72.  
  73. Sub DeleteContextMenu()
  74.  
  75.     On Error Resume Next
  76.     CommandBars("ReportShortcutMenu").Delete
  77.  
  78. End Sub
Mar 8 '23 #3
MikeTheBike
639 Recognized Expert Contributor
Hi All

I have never used 365 so this may be irrelevant, but I suspect not.

Have you set the Shortcut Menu Bar property for the Form or Control in the properties Other Tab.

The code creating the shortcuts will need running ij the session before they appear inthe list for selection.

HTH

MTB
Mar 8 '23 #4
NeoPa
32,564 Recognized Expert Moderator MVP
Hi bounthong.

That is somewhat better. Clearly there is little understanding of what the code does so that would be harder to explain.

By the way - if you have a link to the original thread that MTB was involved in you may post it in here so others may view it in case that can help. While hijacks are not allowed, links to other threads certainly are.

@MTB.

Not sure I understand you correctly. Are you saying the code must be run before the db designer can design it into their Report object? That seems awkward at best.
Mar 8 '23 #5
bounthong
3 New Member
Hi NeoPa,

I have tried different ways, including calling the sub that creating short cut menu in form_load event. As said, there was no error message from the system, it looks like everything is correct. But when the the form is open, right mouse click shows pop-up with standard short cut menu of ms access but not the expected one that should have been created by the sub mentioned.

Anyway, I have resolved my problem already with another method. I disabled all menus and short cut menu, and created custom ribbons for my purpose instead.

Thanks.
Mar 9 '23 #6
MikeTheBike
639 Recognized Expert Contributor
Hi NeoPa

Yes, in my experience since the days of office 97 to before ribbons were forced on us in 2007, Toolbars created in code don't seem to exist until the code creating them has run, which makes sense. Although toolbars so created will now appear on an Addin tab. I now define my own ribbons not toolbars, but the short cut menus still work as the y did pre-ribbons. It is inconvenient having to run the creating code before they appear in the design drop list, but if you know the designated name/title of the shortcut to be created you can type it in (I believe!).

MTB
Mar 9 '23 #7
NeoPa
32,564 Recognized Expert Moderator MVP
Hi Mike.

I'm afraid I still take advantage of the old CommandBars and CommandBarButto ns which, as you say, still work and can be found within the AddIn Toolbar^H^H^H^H ^H^H^HRibbon.
Mar 9 '23 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

10
2546
by: Lex | last post by:
I am writing a C# app that has a Menu. Some of the menu items will have short cuts that do not exist in the Shortcut enum. I would like the custom shortcuts to appear on the menu but as far as I can tell there is no way to add a short cut that is not in the Shortcut enum. I have my on keyboard hook so I am not worried about the custom...
3
2705
by: Terry Bell | last post by:
I have some code that adds entries to the "Module Compiled" popup menu. Works fine in A97. You can open a module, right click, and the new entries are there for you to click. I converted it to A2000, and reapplied the new entries. But now when you open a module and right click (in A2K), the new entries are nowhere to be seen. If (while in...
2
3789
by: JMCN | last post by:
hi i'm having a problem with the customize a shortcut menu. i read the ms office assistance: customize a shortcut menu/delete a command or add to a shortcut menu and followed the simple directions. i tried both but for some reason i cannot delete the categories called "filter", "form", etc. eventually i would like to add commands to the...
12
6744
by: downwitch | last post by:
Hi all, I've read through the archives on this, and scoured the web, to little avail. There has to be a way to move custom menu bars (or menubars, or command bars, or popup command bars, or whatever) from one database to another, because it's an interface import option. I'm happy to slog through coding it myself, but I need a few...
3
2515
by: munkee | last post by:
Hi all, I have been playing with pivotcharts lately to display my data from my database. I have since found however that I will need to get rid of a lot of the "options" a user has to mess around with when I distribute out my database. One of the easiest ways to do this has been to disable all menus and shortcut menus in my database using...
3
13976
beacon
by: beacon | last post by:
Hi everybody, I'm using Access 2010, but the format for the database is .mdb because I'm not ready to fully convert it to Access 2010 and the .accdb format. I've been reading up on how to create Shortcut Menus in Access 2010 using VBA and I'm pretty confident I understand how most of it works...meaning that I can create a custom shortcut...
3
3874
AdamHope
by: AdamHope | last post by:
I want to create a custom shortcut menu bar (MS Access 2003), but include the "Filter for" option, which is in the default menu bar - http://img201.imageshack.us/img201/5405/filterfordefault.jpg I can drag this option to a custom menu, but this then removes it from all default menus. How can I make a copy of this, or create a new one? I...
1
1328
by: husseinspiky | last post by:
please i need help with how can I create custom shortcut menus that appear when you right-click forms because i want to prevent the design view option thank you,
1
1155
Ashish Bisht
by: Ashish Bisht | last post by:
Hi everyone, I have been working on a project related to javascript and want to know your views on creating custom Hamburger menu using jquery which is a symbol consisting of three parallel horizontal lines and used as similar to button in graphical user interfaces. I am also very curious about various other java programming questions and answers...
2
7322
by: EnglishMon | last post by:
Hi I created an MS Access database in the 90's and it has gone through many Access versions and has always had the following fault that I do not know how to correct. On one of the forms I created a custom Shortcut Menu designed for that form only, but it also appears on the other forms too even though it is not selected in their Shortcut Menu...
0
7497
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8010
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7530
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6119
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5414
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3530
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1994
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1111
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
812
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.