Assign Ctrl+P for Print Command in VBA instead of Alt+P (1 Viewer)

accessonly11

Member
Local time
Today, 11:58
Joined
Aug 20, 2022
Messages
91
dears
how it could be possible to assign ctrl + p key to call print command event through vba, instead of using hotkeys.
thanks
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:58
Joined
May 7, 2009
Messages
19,243
create a macro and name it Autokeys.
see this demo using Ctrl+P.
be warned that this macro overrides the default behavior of Ctrl+P (print).
 

Attachments

  • my_macro.mdb
    104 KB · Views: 147

accessonly11

Member
Local time
Today, 11:58
Joined
Aug 20, 2022
Messages
91
create a macro and name it Autokeys.
see this demo using Ctrl+P.
be warned that this macro overrides the default behavior of Ctrl+P (print).
yes i want to disable default ctrl+p behaviour. and assign it to a command button
 

CJ_London

Super Moderator
Staff member
Local time
Today, 07:58
Joined
Feb 19, 2013
Messages
16,612
here is some code that can easily be adapted to specifically disable ctrl-p

as to assigning 'print' to a command button, depends on what you want to print and how, but to open the print dialog box use

DoCmd.RunCommand acCmdPrint
 

accessonly11

Member
Local time
Today, 11:58
Joined
Aug 20, 2022
Messages
91
You can assign our own preferred shortcuts to many actions using an autokeys macro.

However in this case, there is no need as Ctrl+P is already used to open the Print dialog.
Keyboard shortcuts for Access - Microsoft Support
I am unable to assign "call button click event" action using an autokeys macro. To assign an action to ctrl+p keys combination, i am using this code

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyRight
Call cmdNext_Click
Case vbKeyLeft
Call cmdPrevious_Click
Case Shift = acCtrlMask And vbKeyP
Call cmdInvoice_Click
Case Else
End Select
End Sub

but when ever i press keys combinations for second time it open default print dialog box, how to disable this permanently.
 

Users who are viewing this thread

Top Bottom