By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,493 Members | 1,351 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,493 IT Pros & Developers. It's quick & easy.

Click ok button on print box automatically

P: 54
I have some code on a button to print a query when clicked. Afterwords the print dialog box comes up. I want it to print without this box coming up or some code to just click ok automatically. All print settings have already been set in my code.
Jul 19 '12 #1

✓ answered by zmbd

try the following... it has been proofed.

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenQuery ("Anodic Unload Sheet Query")  
  2. Application.Printer.Orientation = acPRORLandscape  
  3. DoCmd.SetWarnings False 
  4. docmd.printout 
  5. DoCmd.SetWarnings true
I don't usually print directly from a query so I missed this the first time around... my apologies

the
Expand|Select|Wrap|Line Numbers
  1. RunCommand acCmdPrint
is the same as pressing <ctrl+p> or selecting the print icon from the ribbon/toolbar.
-z

Share this Question
Share on Google+
7 Replies


zmbd
Expert Mod 5K+
P: 5,287
Please post your current code using the [code][/code] tags
-z
Jul 19 '12 #2

P: 54
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenQuery ("Anodic Unload Sheet Query")
  2. Application.Printer.Orientation = acPRORLandscape
  3. RunCommand acCmdPrint
Jul 19 '12 #3

zmbd
Expert Mod 5K+
P: 5,287
Expand|Select|Wrap|Line Numbers
  1. DoCmd.SetWarnings false
will suppress messages for action queries... I have not tried it with printouts; however, be careful with this... once set to false all of the warnings are turned off so you can get some very unexpected opppps factor going! When I use this in my code, I always have the argument set back to true in my error traps just incase!

(I have not tested the following);
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenQuery ("Anodic Unload Sheet Query") 
  2. Application.Printer.Orientation = acPRORLandscape 
  3. DoCmd.SetWarnings False
  4. RunCommand acCmdPrint 
  5. DoCmd.SetWarnings true
- please let me know if it works.


-z
Jul 19 '12 #4

P: 54
This doesn't work because the print box is not a warning. It is just the standard box for choosing print settings that you would see if you pressed Ctrl+P on a web page. I just don't want users to bother with that box and for it to print automatically after they push to print button on my form.
Jul 19 '12 #5

zmbd
Expert Mod 5K+
P: 5,287
try the following... it has been proofed.

Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenQuery ("Anodic Unload Sheet Query")  
  2. Application.Printer.Orientation = acPRORLandscape  
  3. DoCmd.SetWarnings False 
  4. docmd.printout 
  5. DoCmd.SetWarnings true
I don't usually print directly from a query so I missed this the first time around... my apologies

the
Expand|Select|Wrap|Line Numbers
  1. RunCommand acCmdPrint
is the same as pressing <ctrl+p> or selecting the print icon from the ribbon/toolbar.
-z
Jul 20 '12 #6

P: 54
Thanks! That's exactly what I needed. I always thought that "RunCommand" and "DoCmd." were kind of the same thing. I am really new to access. I had never even heard of it or written code before about a month ago. :)
Jul 20 '12 #7

zmbd
Expert Mod 5K+
P: 5,287
The runcommand is just like if you clicked on the item in menu/ribbon.
The DoCmd is more like you're running one of the macro commands.

More than likely lines 3 and 5 for the warnings aren't needed... forgot to take them out when I tested

Never made sense to me why one has to use macro stuff in a VBA code other than sheer laziness on the part of the developers!

Being new... yep...
I have several of the "Inside/Out..." books dealing with Access and I also went thru http://msdn.microsoft.com/en-us/library/ee861519.aspx although it reads worse than stereo instructions. The rest of the programing comes from being a very old-school programmer... wrote my first programs using a stack of punch cards :) in COBOL... wow... how time flies when you get old, and have kids!

and I still stumble from time to time... that's why boards like this are so valuable - peers helping peers.... wish the world really worked this way as a whole!

-z
Jul 20 '12 #8

Post your reply

Sign in to post your reply or Sign up for a free account.