Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   Index   Templates   Seminars   TechHelp   Forums   Help   Contact   Join   Order   Logon  
 
Home > TechHelp > Directory > Access > Disable Printing < Who Had Item 2 | Disable Printing 2 >
Back to Disable Printing    Comments List
Pinned    Upload Images   Link   Email  
Transcript
Richard Rost 
            
9 months ago
In today's video, we're going to talk about how to disable printing in your Microsoft Access databases. Today's question comes from Lorenzo in Downers Grove, Illinois, one of my Platinum members. Lorenzo says, "I've got a user that likes to hit Control P to print reports instead of using my print button which also runs code to mark invoices as having been printed. I've already disabled the ribbon and the right-click menu using the techniques you've shown in your security seminar and developer classes. However, is there any way to disable Control P and force them to have to use my print button? I still want to allow them to be able to preview a report before printing it so they don't waste paper, but I want to force them to use my print button to actually send the report to the printer."

I get it. I do this in a lot of my databases too. I want the user to be allowed to see the preview so they can look it over and make sure it's okay before they actually waste paper by sending it down to the printer and ink. Of course, you know ink is expensive too. But I do want them to have to click my print button because you can make another button for them like, you know, "Mark this invoice as printed" or "Mark this order as shipped," but people don't click it.

So I get it. Lorenzo, he wants to make it so that when the user prints the actual invoice, it marks it as it's been printed. Okay.

So let's see how we can disable the different ways to print stuff in Microsoft Access without having to use your button. Okay, because you can do it with VBA code very easily.

So what are the different ways to print a report? Let's say once you've got it previewed, right, because I've shown you guys in a million different videos how to actually preview or print a report. It's just do command open report and then the report name and then how you want to print it. You can send it right to the printer or you can open it up in preview mode. But once you put it in preview mode, what's to stop the user from printing it right from there?

How can you print it? Well, you can hit Control P on the keyboard. That's one thing we have to disable. There's the right-click menu, which is this thing. You right-click on the report and you go to print. That's going to bypass your button too. There's the ribbon. The print preview ribbon pops up anytime you go into preview. And of course, there's your own button.

So what we want to do is make our own button and disable these three things. Have a button where they can preview it, right, but they can't print it from there. And then you'll make another button that they can actually print it from.

And I've also seen companies that wanted to completely disable printing altogether. They want to have reports so they can send them as PDFs or whatever, but they don't want stuff being printed and leaving the building. So I get it. But just keep in mind, anything you can screen capture with the screen capture utility, you can print that too. So I mean, that's, you know.

Alright. So in this lesson, let's start off by seeing how we can disable Control P on the keyboard. This is, of course, a developer-level video. What does that mean? Well, that means if you've never done any VBA programming before, go watch this guy. It's about 20 minutes long. It'll teach you everything you need to know to get started. And also go watch this one too, my if-then video. We're going to use an if-then statement. These are both free videos. They're on my website. They're on my YouTube channel. Go watch them and come on back.

Alright. So here I am in my TechHelp free template. This is a free database. You can grab a copy off my website if you want to. And in here, I've got a customer form and customers can have orders. And on your order, you've got a button right here to preview the invoice for that order. And as you can see, you get the print preview ribbon. You can right-click on here and go to print or you can hit Control P on the keyboard and this thing comes up, the print dialog. This is what we're going to disable first, this guy.

How do we do that? Well, we have to intercept the keystrokes in this report. So how do we do that? Well, we go to design view. We bring up the properties for this report. Now on the event tab, you're going to find a couple of keyboard-related events. There's key up, key down, and key press. We're going to use key down. Key down fires when a key is pressed. Key up fires when that key is released. And then key press is something kind of different where you can actually get the ASCII character code that was pressed. We don't want that for now. We're going to focus on key down. Oh, key down. Oh, key? Oh, key. Key down.

Now, here's a tricky thing, and a lot of people don't know this, but in order for this event to fire on either a form or a report, you have to turn this key preview property on. Very important step, don't forget that, otherwise, none of this will work. Why this doesn't default to yes, it's a long story. But now that we have that, we can go to the key down event, go to the dot, dot, dot, that's going to bring up your VBA code builder.

Alright, here we are. Now, the key down event gets two bits of information. The key code, which is a code representing the key that was pressed, and the shift property. Shift will tell you whether control, shift, or alt was also pressed. So watch this. I'm going to just type in here "message box key code." So it's going to message box whatever key was pressed. Okay, that's all for now. Alright, save it. Come back out here. Let's close this and open the report again.

Okay, now make sure you get focused on here. I'm going to press the P key. Alright, 80. So P is character 80. Alright, I'm going to press the A key and oh, see okay, we didn't--we're still going to get this running because we're not interrupting this at all, which we're going to interrupt this in a minute, so hit cancel. Now I'm going to hit the A key. A is 65. See that? Every character, that's the ASCII representation for it, every character has its own key code. If I press the number 1, it's got a key code, 49. If I press A, it's got a key code, 65, and so on.

Okay? And if you press P, which it turns out just P by itself also opens up the print dialog box. I don't know when they changed this. Alright, Control P does it and also just P by itself. So that's new to me. I tried it in a couple of different databases, and it looks like that's the case. So that they must have changed that recently. Okay?

So we have to intercept both P and Control P. Now, back to our code. In order to intercept these key codes, we're going to use the key code in here. So we're going to say now, if key code equals 80, then we're going to say "message box, 'P was pressed,'" and then "end if." So now it should ignore everything except if the P is pressed. All right, you ready?  Let's come back over here. Always a good idea to close and reopen these things.

OK, I'm going to press A, nothing. B, nothing. D, nothing. P, there it is. "P was pressed." And it still fires up that thing. Likewise, if I press, let's say, Control P, look at that. "P was pressed" also. Now normally, if you wanted to get just Control P, then you'd come in here and say, "and shift equals 2." Shift being 1 is the shift key was pressed. Shift being 2 means the Control key was pressed. And shift being 3 means the Alt key was pressed. But we don't even need that because we're going to trap all instances of P being hit. Alt P, Control P, and Shift P, any of those.

Okay? Now, instead of saying "P was pressed," in here we're going to say, "don't press Control P, use the Print button instead." Alright, the Print button that you have put on the form. Okay? Now, before that happens, I want to cancel the key code. I want to set the key code equals zero. That's going to effectively stop whatever is going on in the background. Make sense? Okay, ready? Save it. Let's give it a quick debug compile. Come back over here. Let's close that and reopen it.

OK, now come over here, hit A, B, nothing, hit P. Ah, "don't press Control P, use the Print button instead." Oh, okay, hit OK. And now, see, notice that, no dialog. Because we set the key code to 0, and that will stop the key from continuing. The key down event actually runs before the key is processed.

Alright, let's make sure Control P works too. Control P. All right, "don't press P, use the print button instead." Set it to zero. See? Maybe Alt P, let's see. Yeah, that's true. We're shutting down all instances of P, folks. All of the P's are stopped. So if Alt P is something on the menu that you want, then that's going to be blocked too. But if you want to block just Control P, like I said, I don't know when they did that. It used to be just Control P printed something. But now apparently just hitting P by itself will launch the print dialog box. That's new. That's new for me.

Alright. Close that. So essentially what you'll do is you'll give the user two buttons here. You'll give them a print preview button and then an actual print button. And the actual print button will be the one that sends it to the printer when they're all set for it. It'll open up the print dialog box.

Alright. And if you look at the button, we built this in my invoicing video. I'll put a link to that down below if you want to learn how this was built. We refresh the record first so it saves everything to the table in case you have any changes, and then it's do command open report, the name of the report, and then acViewPreview.

Okay, acViewPreview. There are different ones in here. Preview gives you print preview. Normal opens up the print dialog and sends it right to the printer. Okay, and then there's all kinds of other stuff in here too. Alright, we're going to go back to preview. And you're just going to make a second button to actually do the printing.

Okay, so we've covered Control P or just regular P. There are still two more ways your user can print this thing though. They can use the right-click menu or they can use the ribbon. Alright, when you open this thing up, you get this. There's the print dialog right there. Or you can go right-click and then print. How do we shut these off? Well, we'll cover the right-click menu in tomorrow's video, part two.

So tune in tomorrow, same bat time, same bat channel. Or if you're a member, you can watch it right now because members get to watch stuff as soon as it's made. You don't have to wait for it to be released to the general public. It's one of the benefits of being a member. And then in part three, I will show you how to disable the print preview ribbon across the top of the screen. So that's all coming up. And I also cover a lot of stuff like this in my security seminar where I show you how to disable menus and create custom workflows and control who can do what in your database. We set up passwords, all that good stuff. So that's covered in my security seminar.

And in my Access Developer 44 class, I show you how to build custom ribbons and then we continue on with right-click menus and all that good stuff. So lots of stuff in my full courses. But this is part one for disabling printing. Part two will cover the right-click menu. Part three will cover the ribbon. That's going to be your TechHelp video for today.

I hope you learned something. Live long and prosper, my friends. I'll see you tomorrow for part 2.

TOPICS
Disabling printing in Microsoft Access databases
Disabling the Control P keyboard shortcut for printing reports
Leaving the option to preview reports open in Access
Forcing users to use a specific print button that includes custom code
The importance of a print button that also marks invoices as printed
Stopping users from using the right-click menu to print in Access
Disabling the ribbon's print preview feature in Access
Allowing report preview without the ability to directly print
Different ways reports can be printed in Access
Using VBA to intercept print commands and disable certain shortcuts
Key events in Access reports: Key Down, Key Up, and Key Press
Key Preview property's role in Access's key event handling
Using the Key Down event to suppress printing shortcuts
Intercepting keystrokes using the Key Preview event
Handling the KeyCode attribute in VBA for print commands
Blocking the Control P command to prevent behind-the-scenes printing
Using a message box to warn users about disabled print shortcuts
Setting KeyCode to zero to prevent default printing actions
Making sure all instances of the P key are intercepted
Creating custom print preview and print buttons in Access forms
Distinguishing between different viewing modes in Access

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Disable Printing.
 

 
 
 

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 2024 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 12/14/2024 8:40:41 AM. PLT: 1s