setting printer for pdf creation then reset default printer
-
- 5StarLounger
- Posts: 1148
- Joined: 08 Feb 2010, 21:27
setting printer for pdf creation then reset default printer
I have a need to create a pdf file from a report, but i also have a need to be able to print the report.
How would i set the printer to a pdf creater like PrimoPDF then after creating the pdf, reset the printer to the default again.
How would i set the printer to a pdf creater like PrimoPDF then after creating the pdf, reset the printer to the default again.
-
- 3StarLounger
- Posts: 287
- Joined: 09 Mar 2010, 23:16
- Location: Canberra Australia
Re: setting printer for pdf creation then reset default prin
If you use Stephan Leban's ConvertReportToPDF then you don't need to worry about changing printers.
But here is some code on how to change printers.
But here is some code on how to change printers.
Last edited by JohnH on 16 Nov 2010, 10:17, edited 2 times in total.
Regards
John
John
-
- Administrator
- Posts: 78589
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: setting printer for pdf creation then reset default prin
First, run this code:
Find the number corresponding to the PrimoPDF printer. Let's say it's number 4.
You can now use
Code: Select all
Sub ListPrinters()
Dim i As Integer
For i = 0 To Application.Printers.Count - 1
Debug.Print i, Application.Printers(i).DeviceName
Next i
End Sub
You can now use
Code: Select all
Dim prt As Printer
' Store current printer in variable
Set prt = Application.Printer
' Switch to PDF
Set Application.Printer = Application.Printers(4)
' Print something to PDF
...
' Restore original printer
Set Application.Printer = prt
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 1148
- Joined: 08 Feb 2010, 21:27
Re: setting printer for pdf creation then reset default prin
Thank you John and Hans
-
- 5StarLounger
- Posts: 1148
- Joined: 08 Feb 2010, 21:27
Re: setting printer for pdf creation then reset default prin
When using LeBans ConvertReportToPDF can you nominate a report and use a where clause too?JohnH wrote:If you use Stephan Leban's ConvertReportToPDF then you don't need to worry about changing printers.
But here is some code on how to change printers.
Or do i need to make a special query to use criteria?
-
- Administrator
- Posts: 78589
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: setting printer for pdf creation then reset default prin
You can only specify a report name. The code uses DoCmd.OutputTo to produce a snapshot file which in its turn is converted to PDF. OutputTo doesn't let you specify a where clause.
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 1148
- Joined: 08 Feb 2010, 21:27
Re: setting printer for pdf creation then reset default prin
Thanks Hans, i thought as much after looking at the code.
Looks like i will have to change the SQL of the query behind the report or use a predetermined query.
Or maybe use PDF995, even this way i need to setup PDF995 as a printer on each PC that will use the database.
Thinks i'll go with the SQL or fixed query idea.
Another question: Does it work in an MDE database?
Looks like i will have to change the SQL of the query behind the report or use a predetermined query.
Or maybe use PDF995, even this way i need to setup PDF995 as a printer on each PC that will use the database.
Thinks i'll go with the SQL or fixed query idea.
Another question: Does it work in an MDE database?
-
- Administrator
- Posts: 78589
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: setting printer for pdf creation then reset default prin
Yes, it should, as long as the two DLLs that come in the ReportToPDF zip file are in the same folder as the (.mdb or .mde) database or in the user's Windows32 folder.
Best wishes,
Hans
Hans
-
- 5StarLounger
- Posts: 1148
- Joined: 08 Feb 2010, 21:27
Re: setting printer for pdf creation then reset default prin
Thank you i'll try it.
-
- 5StarLounger
- Posts: 1148
- Joined: 08 Feb 2010, 21:27
Re: setting printer for pdf creation then reset default prin
Another question, I copied the modReportToPDFinto my database from LeBans mdb and i get the following error:
User defined type not defined
on the following command:
Set clsDialog = New clsCommonDialog
What dll or ocx do i need to use in references?
User defined type not defined
on the following command:
Set clsDialog = New clsCommonDialog
What dll or ocx do i need to use in references?
Last edited by Pat on 17 Nov 2010, 01:11, edited 1 time in total.
-
- 5StarLounger
- Posts: 1148
- Joined: 08 Feb 2010, 21:27
Re: setting printer for pdf creation then reset default prin
I needed to copy the module clsCommonDialog from LeBans mdb to mine.
-
- Administrator
- Posts: 78589
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: setting printer for pdf creation then reset default prin
Alternatively, you could use Application.FileDialog - this has been available since Access 2002. But the class module works well so there is no real need to switch.
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 287
- Joined: 09 Mar 2010, 23:16
- Location: Canberra Australia
Re: setting printer for pdf creation then reset default prin
The code uses OutputTo which like (SendObject) does not support a Where clause, but there is a way around this that I use often.Pat wrote: When using LeBans ConvertReportToPDF can you nominate a report and use a where clause too?
Or do i need to make a special query to use criteria?
If you open the report in Preview Mode using a Where clause, then run the code while the report is open, the currently open report is the one used by OutputTo (or SendObject), and so the Where clause remains in effect.
Regards
John
John
-
- 5StarLounger
- Posts: 1148
- Joined: 08 Feb 2010, 21:27
Re: setting printer for pdf creation then reset default prin
Bugger, oh excuse me.
I have just completed changing queries behind the report to insert a WHERE clause.
I seem to remember doing what you have said to do years ago.
Oh well i could undo all that code i guess, it's not that much anyway.
Thanks John.
I have just completed changing queries behind the report to insert a WHERE clause.
I seem to remember doing what you have said to do years ago.
Oh well i could undo all that code i guess, it's not that much anyway.
Thanks John.
-
- 5StarLounger
- Posts: 1148
- Joined: 08 Feb 2010, 21:27
Re: setting printer for pdf creation then reset default prin
I have decided to go with your suggestion John, and it works beautifully.
-
- 3StarLounger
- Posts: 331
- Joined: 11 Feb 2010, 03:55
- Location: Land O Lakes, FL
Re: setting printer for pdf creation then reset default prin
In the long run, I think you'll find it better to get away from using the WHERE parameter in docmd.openReport. I'll use a named query as recordsource for a report, but then form the SQL in code and modify the query prior to opening the report. Besides being able to use "ConvertReportToPDF" (which I use also), it is also useful when I want to export the query to Excel, or when I have an SQL Server backend, and it is more efficient to use a pass-through query.Pat wrote:Looks like i will have to change the SQL of the query behind the report or use a predetermined query.
Or maybe use PDF995, even this way i need to setup PDF995 as a printer on each PC that will use the database.
Thinks i'll go with the SQL or fixed query idea.
Mark Liquorman
Land O Lakes, FL
see my website http://www.liquorman.net for Access Tips and Tricks, and for my Liquorman Utilities.
Land O Lakes, FL
see my website http://www.liquorman.net for Access Tips and Tricks, and for my Liquorman Utilities.
-
- 3StarLounger
- Posts: 287
- Joined: 09 Mar 2010, 23:16
- Location: Canberra Australia
Re: setting printer for pdf creation then reset default prin
Personally, I will keep using them 95% of the time, where I have no need to Export to Excel.In the long run, I think you'll find it better to get away from using the WHERE parameter in docmd.openReport.
One comment that has been made is that some people are moving away from "ConvertReporttoPDF" as Access 2010 is said to have removed support for Snapshots.
Access 2010 has removed Snapshot viewer, and removed all reference to snapshots in the interface, but they have not actually removed snapshots.
So ConvertReporttoPDF does still work with 2010.
Regards
John
John