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 menu, register it (for lack of a better term) so it displays in a form's/report's shortcut menu property dropdown, and have it display the commands.
However, I'm at a point now where I would like to create a custom sub/function and attach it to a command to be included on the shortcut menu for one or more forms/reports. I can create a custom sub/function and I know that I can attach it to a command button using the following:
What I don't know how to do is to setup the sub/function so that it knows which form/report is calling the sub/function so that the name of the form/report can be used in the sub/funtion.
For instance, one of the things I'd like to do is modify the "Email as Attachment" command button so that it will always send as PDF instead of prompting the user for a list of choices (like .xps, .xlsx, etc.). If I was writing this as a private sub/function for a specific form/report, I would use Me.Name, but that won't work if I create the sub/function in a module (only public subs/function can be used in a module, right??).
In case it's needed, here's the code I'm using to create my custom shortcut menu, which I got from the Access Blog article written by Edwin Blancovitch:
Thanks,
beacon
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 menu, register it (for lack of a better term) so it displays in a form's/report's shortcut menu property dropdown, and have it display the commands.
However, I'm at a point now where I would like to create a custom sub/function and attach it to a command to be included on the shortcut menu for one or more forms/reports. I can create a custom sub/function and I know that I can attach it to a command button using the following:
Code:
cmbControl.OnAction = "=MySubFunction()"
For instance, one of the things I'd like to do is modify the "Email as Attachment" command button so that it will always send as PDF instead of prompting the user for a list of choices (like .xps, .xlsx, etc.). If I was writing this as a private sub/function for a specific form/report, I would use Me.Name, but that won't work if I create the sub/function in a module (only public subs/function can be used in a module, right??).
In case it's needed, here's the code I'm using to create my custom shortcut menu, which I got from the Access Blog article written by Edwin Blancovitch:
Code:
Option Compare Database Option Explicit Sub CreateReportShortcutMenu() Dim cmbReportShortcutMenu As Office.CommandBar Dim cmbControl As Office.CommandBarControl 'On Error Resume Next 'Delete the command bar if it already exists DeleteContextMenu ' Create the shortcut menu. Set cmbReportShortcutMenu = CommandBars.Add("ReportShortcutMenu", msoBarPopup) With cmbReportShortcutMenu ' Add the Print command. Set cmbControl = .Controls.Add(msoControlButton, 2521) ' Change the caption displayed for the control. cmbControl.Caption = "Quick Print" ' Add the One Page command. Set cmbControl = .Controls.Add(msoControlButton, 5) ' Add the Two Pages command. Set cmbControl = .Controls.Add(msoControlButton, 639) ' Add the Print command. Set cmbControl = .Controls.Add(msoControlButton, 15948) ' Change the caption displayed for the control. cmbControl.Caption = "Select Pages" ' Add the Page Setup... command. Set cmbControl = .Controls.Add(msoControlButton, 247) ' Change the caption displayed for the control. cmbControl.Caption = "Page Setup" ' Add the Mail Recipient (as Attachment)... command. Set cmbControl = .Controls.Add(msoControlButton, 2188) ' Start a new group. cmbControl.BeginGroup = True ' Change the caption displayed for the control. cmbControl.Caption = "Email Report as an Attachment" ' Add the PDF or XPS command. Set cmbControl = .Controls.Add(msoControlButton, 12499) ' Change the caption displayed for the control. cmbControl.Caption = "Save as PDF/XPS" ' Add the Close command. Set cmbControl = .Controls.Add(msoControlButton, 923) ' Start a new group. cmbControl.BeginGroup = True ' Change the caption displayed for the control. cmbControl.Caption = "Close Report" '******************************************************* '* If I was going to use a custom sub/function, '* this an example of how I would at least start it '******************************************************* ' Add a blank command Set cmbControl = .Controls.Add(msoControlButton, 1) cmbControl.Caption = "Email As PDF" cmbControl.OnAction = "=MySubFunction()" End With Set cmbControl = Nothing Set cmbReportShortcutMenu = Nothing End Sub Sub DeleteContextMenu() On Error Resume Next CommandBars("ReportShortcutMenu").Delete End Sub
beacon
Comment