473,386 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Defining a non-default printer for specific reports

I have two reports I want printed with Cute PDF Writer. Right now, the user has to select this printer, but I want it bound to the reports. I used this technique with Access 97 - I set the printer as part of the Design mode and this particular printer becomes the default for the report. Access 2003 doesn't seem to work the same way. How can I go about this?
Jul 17 '07 #1
7 23104
puppydogbuddy
1,923 Expert 1GB
I have two reports I want printed with Cute PDF Writer. Right now, the user has to select this printer, but I want it bound to the reports. I used this technique with Access 97 - I set the printer as part of the Design mode and this particular printer becomes the default for the report. Access 2003 doesn't seem to work the same way. How can I go about this?
Here is code from the tips page of www.aadconsulting.com that will enable you to switch printers for the report:

Fellow Access develepor, Mark Plumpton, of customdata.co.nz, has kindly provided sample code for easily switching printers on the fly while printing Access reports, with code as simple as this...

SaveDefaultPrinter
DefaultPrinter = "HP Laserjet (A3)"
DoCmd.OpenReport "rptTest", acViewNormal
RestoreDefaultPrinter

Download these demo Access97/2000 databases, which include a class module that performs the function of listing and switching default printers.

http://www.aadconsulting.com/printers.zip

The code is also an excellent example of how you can use classes in your MS Access applications.
Jul 17 '07 #2
Thank you for the information. The issue is slightly more complicated. The application is inherited and the reports, for reasons I have yet to determine, can only be run by macro. Can the first two lines be run as an On Open event and the last one run as On Closed?


Here is code from the tips page of www.aadconsulting.com that will enable you to switch printers for the report:

Fellow Access develepor, Mark Plumpton, of customdata.co.nz, has kindly provided sample code for easily switching printers on the fly while printing Access reports, with code as simple as this...

SaveDefaultPrinter
DefaultPrinter = "HP Laserjet (A3)"
DoCmd.OpenReport "rptTest", acViewNormal
RestoreDefaultPrinter

Download these demo Access97/2000 databases, which include a class module that performs the function of listing and switching default printers.

http://www.aadconsulting.com/printers.zip

The code is also an excellent example of how you can use classes in your MS Access applications.
Jul 18 '07 #3
puppydogbuddy
1,923 Expert 1GB
Thank you for the information. The issue is slightly more complicated. The application is inherited and the reports, for reasons I have yet to determine, can only be run by macro. Can the first two lines be run as an On Open event and the last one run as On Closed?
I believe the first two lines have to be executed before the report is opened, and the last line has to be executed right after the report is closed. but go ahead and try your idea...it might work. If it doesn't work post the details of the macro.
Jul 18 '07 #4
You were correct about the first two lines needed to be executed before the report prints. I added a line in the macro: RunCode with SaveDefaultPrinter as the parameter and that works. When I try the same idea with DefaultPrinter = "Win2PDF", I get an error. Since I have have limited experience with macros, should I place the first two lines in a global function? Is there some way to call the DefaultPrinter without a parameter?

I believe the first two lines have to be executed before the report is opened, and the last line has to be executed right after the report is closed. but go ahead and try your idea...it might work. If it doesn't work post the details of the macro.
Jul 23 '07 #5
ADezii
8,834 Expert 8TB
I have two reports I want printed with Cute PDF Writer. Right now, the user has to select this printer, but I want it bound to the reports. I used this technique with Access 97 - I set the printer as part of the Design mode and this particular printer becomes the default for the report. Access 2003 doesn't seem to work the same way. How can I go about this?
Here are 2 Routines along with their associated Calls, which should prove very helpful to you. They are basically self-explanatory, but if you need further assistance, please feel free to ask:
  1. To Print a specific Report to a specific Printer:
    Expand|Select|Wrap|Line Numbers
    1. Public Sub PrintReport(strReport As String, strPrinter As String)
    2. 'Opens a report in Preview view, prints to a specific Printer,
    3. 'then Closes the Report
    4.  
    5. Dim rpt As Report
    6.  
    7. DoCmd.OpenReport strReport, View:=acViewPreview, WindowMode:=acHidden
    8.  
    9. Set rpt = Reports(strReport)
    10.  
    11. 'Set to the specific Printer
    12. Set rpt.Printer = Application.Printers(strPrinter)
    13.  
    14. DoCmd.OpenReport strReport
    15. DoCmd.Close acReport, strReport
    16. End Sub
    Expand|Select|Wrap|Line Numbers
    1. 'To Call this Sub-Routine
    2. Call PrintReport("Report1", "Cute PDF Writer")
  2. To change the Default Printer, Print a specific Report, then revert back to the previous Default Printer:
    Expand|Select|Wrap|Line Numbers
    1. Public Sub ChangeDefaultPrinterAndPrint(strReport As String, strPrinter As String)
    2. 'Change the printer, and print. This will only work if your report
    3. 'is set up to print to the default printer.
    4.  
    5. Set Application.Printer = Application.Printers(strPrinter)
    6. DoCmd.OpenReport strReport
    7.  
    8. 'Set the default printer back the way it was.
    9. Set Application.Printer = Nothing
    10. End Sub
    Expand|Select|Wrap|Line Numbers
    1. 'To Call this Sub-Routine
    2. Call ChangeDefaultPrinterAndPrint("Report1", "Cute PDF Writer")
  3. If you insist on using Macros:
    1. Change the 2 Sub-Routines to Public Functions.
    2. Use the RunCode Action within the Macros to call the Functions and pass to it the required Parameters (2).
Jul 24 '07 #6
Thanks for the feedback. This should work. As for insisting on using macros, I am a VBA coding guy. I have avoided macros because I want to keep objects together. I inherited this pasta code. A client had several people work on it over the years - none of whom are Access programmers. Hence, it does strange and wonderful things.

Here are 2 Routines along with their associated Calls, which should prove very helpful to you. They are basically self-explanatory, but if you need further assistance, please feel free to ask:
  1. To Print a specific Report to a specific Printer:
    Expand|Select|Wrap|Line Numbers
    1. Public Sub PrintReport(strReport As String, strPrinter As String)
    2. 'Opens a report in Preview view, prints to a specific Printer,
    3. 'then Closes the Report
    4.  
    5. Dim rpt As Report
    6.  
    7. DoCmd.OpenReport strReport, View:=acViewPreview, WindowMode:=acHidden
    8.  
    9. Set rpt = Reports(strReport)
    10.  
    11. 'Set to the specific Printer
    12. Set rpt.Printer = Application.Printers(strPrinter)
    13.  
    14. DoCmd.OpenReport strReport
    15. DoCmd.Close acReport, strReport
    16. End Sub
    Expand|Select|Wrap|Line Numbers
    1. 'To Call this Sub-Routine
    2. Call PrintReport("Report1", "Cute PDF Writer")
  2. To change the Default Printer, Print a specific Report, then revert back to the previous Default Printer:
    Expand|Select|Wrap|Line Numbers
    1. Public Sub ChangeDefaultPrinterAndPrint(strReport As String, strPrinter As String)
    2. 'Change the printer, and print. This will only work if your report
    3. 'is set up to print to the default printer.
    4.  
    5. Set Application.Printer = Application.Printers(strPrinter)
    6. DoCmd.OpenReport strReport
    7.  
    8. 'Set the default printer back the way it was.
    9. Set Application.Printer = Nothing
    10. End Sub
    Expand|Select|Wrap|Line Numbers
    1. 'To Call this Sub-Routine
    2. Call ChangeDefaultPrinterAndPrint("Report1", "Cute PDF Writer")
  3. If you insist on using Macros:
    1. Change the 2 Sub-Routines to Public Functions.
    2. Use the RunCode Action within the Macros to call the Functions and pass to it the required Parameters (2).
Jul 26 '07 #7
Hi, I'm just trying to change the printer when I need to print something specific in a forum. I used your code from the print.zip and it seems to be working it changes the printer to the one I want and back, but it still prints to the original printer. I debugged it and it does do the change to the printer I want before
DoCmd.PrintOut acSelection
So I don't understand why this would be. I didn't change your module I only put your module in my project and the code you suggested in the forum code. I don't understand why it would do this.
Also this is for one computer and I know the printer I want to send it to. Theres no way to just tell it what printer to print to and not worry about changing defult printers?
Thanks
Kucster
Aug 3 '07 #8

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

Similar topics

14
by: mirnazim | last post by:
Hi, There are great Python Web Application Framework. But most of them are meant for content oriented web apps. Is there something that can ease the development of application that are not...
7
by: Senthilraja | last post by:
I have the following program using templates. Someone please let me know the syntax to be used for defining the member functions push, pop etc. as non-inline functions. #include <iostream>...
19
by: Christian Engström | last post by:
If you have a function that returns something by value, the gcc compiler (version 3.2.3 on Windows XP with MinGW) converts the returned value from the type you specify in the code, to the const...
14
by: Mike Hewson | last post by:
Have been researching as to why: <example 1> class ABC { static const float some_float = 3.3f; }; <end example 1>
23
by: Ken Turkowski | last post by:
The construct (void*)(((long)ptr + 3) & ~3) worked well until now to enforce alignment of the pointer to long boundaries. However, now VC++ warns about it, undoubtedly to help things work on 64...
16
by: Raj Kotaru | last post by:
Hello all, I recently came across the following segment of code that defines a C struct: typedef struct { unsigned char unused_bits:4; unsigned char wchair_state:2; } xyz;
5
by: chrisstankevitz | last post by:
Why does this code only compile if GLOBAL_IN_STRUCT is defined? It creates a templated class C<T> and defines a global operator* that takes a C<T> on the LHS and a T on the RHS. In the...
3
by: Pierre Barbier de Reuille | last post by:
Hi, after reading the article " The Standard Librarian : Defining Iterators and Const Iterators" from Matt Austern:...
7
by: mathieu | last post by:
Hello, I did read the FAQ on template(*), since I could not find an answer to my current issue I am posting here. I have tried to summarize my issue in the following code (**). Basically I am...
13
by: John | last post by:
Is this a valid C++ program that will not crash on any machine? #include <iostream> using namespace std; int main( void ) { int i; cin >i; double X; X = 1123;
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.