I have been trying to put "PrintDialogAccess" into a context menu. I can not find its ID number. Her is what i have been trying.
DetailsPrivate Sub LoadContextMenus()
' load context menu for customer form
Const msoControlButton = 1 Const msoBarPopup = 5
Dim C As Object ' CommandBar Object
On Error Resume Next ' delete menu bar if it exists CommandBars("BasicFBar").Delete 'CommandBars("RecipFBar").Delete CommandBars("PrintFBar").Delete 'CommandBars("MainMenuFBar").Delete 'CommandBars("CustomerFBar").Delete On Error GoTo 0
Set C = CommandBars.Add("BasicFBar", msoBarPopup, False, False) 'C.Controls.Add msoControlButton, CommandBars("Edit").Controls("Cut").ID 'ID = 21 Long way C.Controls.Add msoControlButton, 21 ' Cut C.Controls.Add msoControlButton, 19 ' Copy C.Controls.Add msoControlButton, 22 ' Paste C.Controls.Add msoControlButton, 128 ' Undo C.Controls.Add msoControlButton, 129 ' Redo C.Controls.Add msoControlButton, 2 ' Spelling C.Controls.Add msoControlButton, 108 ' Format Painter C.Controls.Add msoControlButton, 106 ' Close Form C.Controls.Add msoControlButton, 2952 ' Design View
Set C = Nothing
Set C = CommandBars.Add("PrintFBar", msoBarPopup, False, False) C.Controls.Add msoControlButton, 14782 ' Close print Preview 'C.Controls.Add msoControlButton, CommandBars("PrintDialogAccess").Controls("TabPrint").ID
Set C = Nothing
End Sub
All works except the Print(PrintDialogAccess) If i put it in it gives me an error Any help would be much appreciated.
Donald Blackwell
@Reply 8 months ago
I posted your question to CoPilot in ChatGPT 5.1 Smart mode, here is what it returned:
DetailsThe line you commented out throws an error because you cannot copy controls from the internal "PrintDialogAccess" commandbar. Those dialog bars are modal and their controls aren't exposed for reuse. That's why Access blows up.
The fix: ( Goes after your print preview line )
Dim ctl As CommandBarControl
Set ctl = C.Controls.Add(Type:=msoControlButton)
With ctl
.Caption = "Print..."
.OnAction = "MyPrintHandler" ' custom VBA routine
.FaceId = 4 ' printer icon
End With
And in a standard module:
Public Sub MyPrintHandler()
DoCmd.RunCommand acCmdPrint
End Sub
I haven't tested it, but that's what it gave.
Gordon MerkoskyOP
@Reply 8 months ago
Thank you for your help!
Works great!
Gordon MerkoskyOP
@Reply 8 months ago
Well did work great until I hit the Cancel button.
I got around the run time error like this.
Public Sub MyPrintHandler()
On Error Resume Next
DoCmd.RunCommand acCmdPrint
On Error GoTo 0
End Sub
Sorry, only students may add comments.
Click here for more
information on how you can set up an account.
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.
This thread is now CLOSED. If you wish to comment, start a NEW discussion in
Access Developer 45.