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?
7 23104
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.
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.
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.
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.
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:- To Print a specific Report to a specific Printer:
- Public Sub PrintReport(strReport As String, strPrinter As String)
-
'Opens a report in Preview view, prints to a specific Printer,
-
'then Closes the Report
-
-
Dim rpt As Report
-
-
DoCmd.OpenReport strReport, View:=acViewPreview, WindowMode:=acHidden
-
-
Set rpt = Reports(strReport)
-
-
'Set to the specific Printer
-
Set rpt.Printer = Application.Printers(strPrinter)
-
-
DoCmd.OpenReport strReport
-
DoCmd.Close acReport, strReport
-
End Sub
-
'To Call this Sub-Routine
-
Call PrintReport("Report1", "Cute PDF Writer")
- To change the Default Printer, Print a specific Report, then revert back to the previous Default Printer:
- Public Sub ChangeDefaultPrinterAndPrint(strReport As String, strPrinter As String)
-
'Change the printer, and print. This will only work if your report
-
'is set up to print to the default printer.
-
-
Set Application.Printer = Application.Printers(strPrinter)
-
DoCmd.OpenReport strReport
-
-
'Set the default printer back the way it was.
-
Set Application.Printer = Nothing
-
End Sub
-
'To Call this Sub-Routine
-
Call ChangeDefaultPrinterAndPrint("Report1", "Cute PDF Writer")
- If you insist on using Macros:
- Change the 2 Sub-Routines to Public Functions.
- Use the RunCode Action within the Macros to call the Functions and pass to it the required Parameters (2).
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:- To Print a specific Report to a specific Printer:
- Public Sub PrintReport(strReport As String, strPrinter As String)
-
'Opens a report in Preview view, prints to a specific Printer,
-
'then Closes the Report
-
-
Dim rpt As Report
-
-
DoCmd.OpenReport strReport, View:=acViewPreview, WindowMode:=acHidden
-
-
Set rpt = Reports(strReport)
-
-
'Set to the specific Printer
-
Set rpt.Printer = Application.Printers(strPrinter)
-
-
DoCmd.OpenReport strReport
-
DoCmd.Close acReport, strReport
-
End Sub
-
'To Call this Sub-Routine
-
Call PrintReport("Report1", "Cute PDF Writer")
- To change the Default Printer, Print a specific Report, then revert back to the previous Default Printer:
- Public Sub ChangeDefaultPrinterAndPrint(strReport As String, strPrinter As String)
-
'Change the printer, and print. This will only work if your report
-
'is set up to print to the default printer.
-
-
Set Application.Printer = Application.Printers(strPrinter)
-
DoCmd.OpenReport strReport
-
-
'Set the default printer back the way it was.
-
Set Application.Printer = Nothing
-
End Sub
-
'To Call this Sub-Routine
-
Call ChangeDefaultPrinterAndPrint("Report1", "Cute PDF Writer")
- If you insist on using Macros:
- Change the 2 Sub-Routines to Public Functions.
- Use the RunCode Action within the Macros to call the Functions and pass to it the required Parameters (2).
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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>...
|
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...
|
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>
|
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...
|
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;
|
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...
|
by: Pierre Barbier de Reuille |
last post by:
Hi,
after reading the article " The Standard Librarian : Defining Iterators
and Const Iterators" from Matt Austern:...
|
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...
|
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;
|
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,...
|
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$) {
}
...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
| |