Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Developer 45 Lessons    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Context Menus
Gordon Merkosky 
     
2 months ago
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  
       
2 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 Merkosky OP  @Reply  
     
2 months ago
Thank you for your help!
Works great!
Gordon Merkosky OP  @Reply  
     
2 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

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Developer 45 Lessons.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 3/7/2026 12:21:42 AM. PLT: 1s