Printing directly to default printer (1 Viewer)

Capitala

Member
Local time
Today, 12:09
Joined
Oct 21, 2021
Messages
58
Good day very helpful people!
I've a custom shortcut menu bar in my reports. I need to add a button that prints directly (2 copies) to default printer.
I've tried the code:
newMenu.Controls.Add(1, 15948, , , True)
newMenu.Controls.Add 1, 12499, , , True
But both lead to a dialogue box.
Any suggestions?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:09
Joined
May 7, 2009
Messages
19,169
why not use Custom menu (not the built-in):

Code:
Dim btn As CommandBarButton
Set btn = newMenu.Controls.Add
With btn
    .Caption = "Print(default printer)"
    .OnAction = "=fnPrintToDefault()"
    .FaceId = 745
End With
now on a module you create a function fnPrintToDefault():

Code:
Public Function fnPrintToDefault()
    On Error Resume Next
    DoCmd.PrintOut
End Function
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 12:09
Joined
Jul 9, 2003
Messages
16,244
You may find something in Allen Browne's blog here useful:-

 
Last edited:

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 12:09
Joined
Sep 12, 2006
Messages
15,613
Why is printing to the default printer complicated? If you want 2 copies, you could just loop and call the code twice, or hard code it twice. Printing only becomes more awkward if you want a different printer.
 

strive4peace

AWF VIP
Local time
Today, 07:09
Joined
Apr 3, 2020
Messages
1,003
hi @Capitala,

a tables of numbers is helpful in this case.

Numbers
Num, integer, PK, (1,2,3, ... )

In the recordsource of the report, join in the Numbers table and add the Num field. If it will always be 2 copies, put 2 as the criteria for Num. Alternately, you can make it variable by specifying how many copies you want in the WHERE condition clause of OpenReport

There is NO relationship to the Numbers table -- it simply serves to specify how many copies you want ~
 

Capitala

Member
Local time
Today, 12:09
Joined
Oct 21, 2021
Messages
58
why not use Custom menu (not the built-in):

Code:
Dim btn As CommandBarButton
Set btn = newMenu.Controls.Add
With btn
    .Caption = "Print(default printer)"
    .OnAction = "=fnPrintToDefault()"
    .FaceId = 745
End With
now on a module you create a function fnPrintToDefault():

Code:
Public Function fnPrintToDefault()
    On Error Resume Next
    DoCmd.PrintOut
End Function
This code works perfectly, but the issue is that it needs office 16 library reference. On implementing my project, user will need to add it manually. Is there any VBA code to add (Microsoft Office 16.0 Object Library). Thanks in advance
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:09
Joined
May 7, 2009
Messages
19,169
is it not adding automatically?
how did you create Newmenu on post #1 anyway without using
Microsoft Office X.XX Object Library object?
 

Capitala

Member
Local time
Today, 12:09
Joined
Oct 21, 2021
Messages
58
is it not adding automatically?
how did you create Newmenu on post #1 anyway without using
Microsoft Office X.XX Object Library object?
I've created the Newmenu using the above code but I'm talking about the case upon deploying my program on another machine in which the office 16.0 reference is not activated. i.e. every time I place my program on any other machine, I need to enable the reference manually. In case of my absence, how would the user do that?
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 12:09
Joined
Jul 9, 2003
Messages
16,244
I had a vague notion that what you describe is possible so I did a quick internet search and found this link:-


I have no idea if that's of any use but it does seem to support my suspicion that it is possible and I'm sure that with that link you should be able to pick out some suitable search terms to do a bit of Google searching on your own and maybe come up with an answer. if you do please post it back here!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:09
Joined
May 7, 2009
Messages
19,169
you only create the shortcut menu once.
so you add reference to microsoft office object library first.
when you run the sub/func that create your Custom shortcut menu, then
you can remove the Reference again.

you don't create (and recreate) your custom shortcut menu.
you create it only once.
 

Users who are viewing this thread

Top Bottom