MS access- Fix key capture code to Ctrl-p not any combo with P

I am using the code below to stop users form printing forms, but for some reason, it is stopping any use the key P. Can you please help me solve this (i'm a bit slow on coding, so please give correct code when posting answer).
Private Sub TabCtl24_KeyDown(KeyCode As Integer, Shift As Integer)

    If KeyCode = vbKeyP And vbKeyControl Then
        MsgBox "Print disabled on form, Use reports to print"
        KeyCode = 0
    End If

End Sub

Open in new window

tesla_VAsked:
Who is Participating?
 
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPConnect With a Mentor Commented:


Try:

Private Sub TabCtl24_KeyDown(KeyCode As Integer, Shift As Integer)

    If KeyCode = 80 And Shift = 2 Then
        MsgBox "Print disabled on form, Use reports to print"
        KeyCode = 0
    End If

End Sub

Open in new window

0
 
Martin LissOlder than dirtCommented:

If (KeyCode = vbKeyP) And (Shift = vbCtrlMask) Then...
0
 
Dale FyeCommented:
If this is in Access, you will need to use the acCtrlMask constant, instead of the vbCtrlMask

If (KeyCode = vbKeyP) And (Shift = acCtrlMask) Then...
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Simply create an AutoKeys Macro as shown below.  And you can add several other keys as well.  I have an AutoKeysSecured that I copy to AutoKeys before deployment that traps loads of keys.

mx
Capture1.gif
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Auto Keys Secured.  Imagine adding code to trap all of these combinations!

mx
Capture1.gif
0
 
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPCommented:
mx,

It is my understanding that tesla_V want ctrl-p to work for reports.

By using Autokeys, that  will turn it off globally even for reports.    
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Yep ...missed that.  Your code is the solution.

mx
0
 
tesla_VAuthor Commented:
easy to use, copy and paste it in.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.