Click ok button on print box automatically

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Becker
    New Member
    • Jul 2012
    • 54

    Click ok button on print box automatically

    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.
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    Please post your current code using the [CODE][/CODE] tags
    -z

    Comment

    • Becker
      New Member
      • Jul 2012
      • 54

      #3
      Code:
      DoCmd.OpenQuery ("Anodic Unload Sheet Query")
      Application.Printer.Orientation = acPRORLandscape
      RunCommand acCmdPrint

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        Code:
        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);
        Code:
        DoCmd.OpenQuery ("Anodic Unload Sheet Query") 
        Application.Printer.Orientation = acPRORLandscape 
        DoCmd.SetWarnings False
        RunCommand acCmdPrint 
        DoCmd.SetWarnings true
        - please let me know if it works.


        -z

        Comment

        • Becker
          New Member
          • Jul 2012
          • 54

          #5
          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.

          Comment

          • zmbd
            Recognized Expert Moderator Expert
            • Mar 2012
            • 5501

            #6
            try the following... it has been proofed.

            Code:
            DoCmd.OpenQuery ("Anodic Unload Sheet Query")  
            Application.Printer.Orientation = acPRORLandscape  
            DoCmd.SetWarnings False 
            docmd.printout 
            DoCmd.SetWarnings true
            I don't usually print directly from a query so I missed this the first time around... my apologies

            the
            Code:
            RunCommand acCmdPrint
            is the same as pressing <ctrl+p> or selecting the print icon from the ribbon/toolbar.
            -z

            Comment

            • Becker
              New Member
              • Jul 2012
              • 54

              #7
              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. :)

              Comment

              • zmbd
                Recognized Expert Moderator Expert
                • Mar 2012
                • 5501

                #8
                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
                Last edited by zmbd; Jul 20 '12, 04:07 PM. Reason: spell check. :)

                Comment

                Working...