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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:

If (KeyCode = vbKeyP) And (Shift = vbCtrlMask) Then...
0
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPDesigner and DeveloperCommented:


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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dale FyeOwner, Developing Solutions LLCCommented:
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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
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 Architect / Systems AnalystCommented:
Auto Keys Secured.  Imagine adding code to trap all of these combinations!

mx
Capture1.gif
0
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPDesigner and DeveloperCommented:
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 Architect / Systems AnalystCommented:
Yep ...missed that.  Your code is the solution.

mx
0
tesla_VAuthor Commented:
easy to use, copy and paste it in.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.