Setting up printer Progamatically

T

TomT

I have a routine that works fine on some systems, but not on others. It's an
Access 2003 database, where I check for the existence of a certain printer,
and if it's there, go ahead and set it as the default printer, set some
attributes, and open a report in print preview.

I'm at a loss as to why this gives an error 5 on some systems. Here's the
code:

Public Sub SetPDFPrinter(rptName As String, criteria As String, intOrient As
Integer)

Dim prt As Printer
Dim msg As String

If PDFPrinterExists = True Then 'this module

Set prt = Application.Printers("\\CROPRT001\pdfFactory Pro")

prt.Orientation = intOrient

Set Application.Printer = prt

DoCmd.OpenReport rptName, acViewNormal, , criteria, , "OpenPDF"

Application.Printer = Nothing

Else

msg = "This requires installation of the pdfFactory Pro printer.
" & _
"You do not have this printer installed. Please contact " & _
"the MIS department to assist you installing this printer."

MsgBox msg, vbOKOnly + vbCritical, "Missing Printer"

End If

Exit Sub

When it fails, it does so on the line: Set prt =
Application.Printers(""\\CROPRT001\pdfFactory Pro"), with error 5 invalid
procedure call.

The printer is installed on the system, and works if I just preveiw the
report normally, and then go thru the process to print it to the pdf printer.

I figure I'm missing something, but cannot see what it is, so far anyway.
There are no missing references either.

Thanks for any help,

TomT
 
P

Peter Yang [MSFT]

Hello Tom,

IT seems the printer settings for the \\CROPRT001\pdfFactory Pro has
issues. Did you confirm the printer work properly from the computers having
this problem? You may check in Notpad and Access print menu.

This issues indicates the initialization error of the printer. Usually it
is caused by some problem in network printer settings in the registry key.
You may want to compare the following registry keys between known good and
problemtic machines.

HKEY_CURRENT_USER\Printers\DevModes2
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Print\Providers\LanMan

Print Services\Servers\<printer name>

If the issue persists, I suggest that you try to use
PrintDevMode/PrintDevNames to see if you could work around this issue

208840.KB.EN-US ACC2000: How to Use Code to Change a Report's Printer
http://support.microsoft.com/default.aspx?scid=KB;EN-US;208840

Hope this is helpful

Best Regards,

Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Partner Support

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

=====================================================



This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
| Thread-Topic: Setting up printer Progamatically
| thread-index: AcWoLv4Ms6rI1S3PQwa9w81OTg9toQ==
| X-WBNR-Posting-Host: 68.67.208.184
| From: "=?Utf-8?B?VG9tVA==?=" <[email protected]>
| Subject: Setting up printer Progamatically
| Date: Tue, 23 Aug 2005 15:07:03 -0700
| Lines: 53
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.access.formscoding
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.access.formscoding:58448
| X-Tomcat-NG: microsoft.public.access.formscoding
|
| I have a routine that works fine on some systems, but not on others. It's
an
| Access 2003 database, where I check for the existence of a certain
printer,
| and if it's there, go ahead and set it as the default printer, set some
| attributes, and open a report in print preview.
|
| I'm at a loss as to why this gives an error 5 on some systems. Here's the
| code:
|
| Public Sub SetPDFPrinter(rptName As String, criteria As String, intOrient
As
| Integer)
|
| Dim prt As Printer
| Dim msg As String
|
| If PDFPrinterExists = True Then 'this module
|
| Set prt = Application.Printers("\\CROPRT001\pdfFactory Pro")
|
| prt.Orientation = intOrient
|
| Set Application.Printer = prt
|
| DoCmd.OpenReport rptName, acViewNormal, , criteria, ,
"OpenPDF"
|
| Application.Printer = Nothing
|
| Else
|
| msg = "This requires installation of the pdfFactory Pro
printer.
| " & _
| "You do not have this printer installed. Please contact "
& _
| "the MIS department to assist you installing this
printer."
|
| MsgBox msg, vbOKOnly + vbCritical, "Missing Printer"
|
| End If
|
| Exit Sub
|
| When it fails, it does so on the line: Set prt =
| Application.Printers(""\\CROPRT001\pdfFactory Pro"), with error 5 invalid
| procedure call.
|
| The printer is installed on the system, and works if I just preveiw the
| report normally, and then go thru the process to print it to the pdf
printer.
|
| I figure I'm missing something, but cannot see what it is, so far anyway.
| There are no missing references either.
|
| Thanks for any help,
|
| TomT
|
|
 
T

TomT

Peter,

Thanks for your reponse. I changed my code to the following, and it now
works in all cases (at least as far as I know right now):

Dim prt As Printer
Dim msg As String
Dim prtLoop As Printer
Dim blnPrinterFound As Boolean

For Each prtLoop In Application.Printers

With prtLoop

If .DeviceName = "\\CROPRT001\pdfFactory Pro" Then

blnPrinterFound = True

Set prt = Application.Printers(.DeviceName)

prt.Orientation = intOrient

Set Application.Printer = prt

DoCmd.OpenReport rptName, acViewNormal, , criteria, ,
"OpenPDF"

Application.Printer = Nothing

Exit For

End If

End With

Next prtLoop

If blnPrinterFound = False Then

msg = "This requires installation of the pdfFactory Pro printer.
" & _
"You do not have this printer installed. Please contact " & _
"the MIS department to assist you installing this printer."

MsgBox msg, vbOKOnly + vbCritical, "Missing Printer"

End If

Thanks for your help,

Tom
 
P

Peter Yang [MSFT]

Hello Tom,

Great to hear the issue is resolve! Your experience will surely benefit the
community. :)

Best Regards,

Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Partner Support

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

=====================================================


This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
| Thread-Topic: Setting up printer Progamatically
| thread-index: AcWqgfau9RJiFWPiTDK1nKrmF8Ptpw==
| X-WBNR-Posting-Host: 68.67.208.184
| From: "=?Utf-8?B?VG9tVA==?=" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: RE: Setting up printer Progamatically
| Date: Fri, 26 Aug 2005 14:06:01 -0700
| Lines: 183
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.access.formscoding
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.access.formscoding:58872
| X-Tomcat-NG: microsoft.public.access.formscoding
|
| Peter,
|
| Thanks for your reponse. I changed my code to the following, and it now
| works in all cases (at least as far as I know right now):
|
| Dim prt As Printer
| Dim msg As String
| Dim prtLoop As Printer
| Dim blnPrinterFound As Boolean
|
| For Each prtLoop In Application.Printers
|
| With prtLoop
|
| If .DeviceName = "\\CROPRT001\pdfFactory Pro" Then
|
| blnPrinterFound = True
|
| Set prt = Application.Printers(.DeviceName)
|
| prt.Orientation = intOrient
|
| Set Application.Printer = prt
|
| DoCmd.OpenReport rptName, acViewNormal, , criteria, ,
| "OpenPDF"
|
| Application.Printer = Nothing
|
| Exit For
|
| End If
|
| End With
|
| Next prtLoop
|
| If blnPrinterFound = False Then
|
| msg = "This requires installation of the pdfFactory Pro
printer.
| " & _
| "You do not have this printer installed. Please contact "
& _
| "the MIS department to assist you installing this
printer."
|
| MsgBox msg, vbOKOnly + vbCritical, "Missing Printer"
|
| End If
|
| Thanks for your help,
|
| Tom
|
| "Peter Yang [MSFT]" wrote:
|
| > Hello Tom,
| >
| > IT seems the printer settings for the \\CROPRT001\pdfFactory Pro has
| > issues. Did you confirm the printer work properly from the computers
having
| > this problem? You may check in Notpad and Access print menu.
| >
| > This issues indicates the initialization error of the printer. Usually
it
| > is caused by some problem in network printer settings in the registry
key.
| > You may want to compare the following registry keys between known good
and
| > problemtic machines.
| >
| > HKEY_CURRENT_USER\Printers\DevModes2
| > HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
| > NT\CurrentVersion\Print\Providers\LanMan
| >
| > Print Services\Servers\<printer name>
| >
| > If the issue persists, I suggest that you try to use
| > PrintDevMode/PrintDevNames to see if you could work around this issue
| >
| > 208840.KB.EN-US ACC2000: How to Use Code to Change a Report's Printer
| > http://support.microsoft.com/default.aspx?scid=KB;EN-US;208840
| >
| > Hope this is helpful
| >
| > Best Regards,
| >
| > Peter Yang
| > MCSE2000/2003, MCSA, MCDBA
| > Microsoft Online Partner Support
| >
| > When responding to posts, please "Reply to Group" via your newsreader
so
| > that others may learn and benefit from your issue.
| >
| > =====================================================
| >
| >
| >
| > This posting is provided "AS IS" with no warranties, and confers no
rights.
| >
| >
| > --------------------
| > | Thread-Topic: Setting up printer Progamatically
| > | thread-index: AcWoLv4Ms6rI1S3PQwa9w81OTg9toQ==
| > | X-WBNR-Posting-Host: 68.67.208.184
| > | From: "=?Utf-8?B?VG9tVA==?=" <[email protected]>
| > | Subject: Setting up printer Progamatically
| > | Date: Tue, 23 Aug 2005 15:07:03 -0700
| > | Lines: 53
| > | Message-ID: <[email protected]>
| > | MIME-Version: 1.0
| > | Content-Type: text/plain;
| > | charset="Utf-8"
| > | Content-Transfer-Encoding: 7bit
| > | X-Newsreader: Microsoft CDO for Windows 2000
| > | Content-Class: urn:content-classes:message
| > | Importance: normal
| > | Priority: normal
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| > | Newsgroups: microsoft.public.access.formscoding
| > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| > | Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.access.formscoding:58448
| > | X-Tomcat-NG: microsoft.public.access.formscoding
| > |
| > | I have a routine that works fine on some systems, but not on others.
It's
| > an
| > | Access 2003 database, where I check for the existence of a certain
| > printer,
| > | and if it's there, go ahead and set it as the default printer, set
some
| > | attributes, and open a report in print preview.
| > |
| > | I'm at a loss as to why this gives an error 5 on some systems. Here's
the
| > | code:
| > |
| > | Public Sub SetPDFPrinter(rptName As String, criteria As String,
intOrient
| > As
| > | Integer)
| > |
| > | Dim prt As Printer
| > | Dim msg As String
| > |
| > | If PDFPrinterExists = True Then 'this module
| > |
| > | Set prt = Application.Printers("\\CROPRT001\pdfFactory
Pro")
| > |
| > | prt.Orientation = intOrient
| > |
| > | Set Application.Printer = prt
| > |
| > | DoCmd.OpenReport rptName, acViewNormal, , criteria, ,
| > "OpenPDF"
| > |
| > | Application.Printer = Nothing
| > |
| > | Else
| > |
| > | msg = "This requires installation of the pdfFactory Pro
| > printer.
| > | " & _
| > | "You do not have this printer installed. Please
contact "
| > & _
| > | "the MIS department to assist you installing this
| > printer."
| > |
| > | MsgBox msg, vbOKOnly + vbCritical, "Missing Printer"
| > |
| > | End If
| > |
| > | Exit Sub
| > |
| > | When it fails, it does so on the line: Set prt =
| > | Application.Printers(""\\CROPRT001\pdfFactory Pro"), with error 5
invalid
| > | procedure call.
| > |
| > | The printer is installed on the system, and works if I just preveiw
the
| > | report normally, and then go thru the process to print it to the pdf
| > printer.
| > |
| > | I figure I'm missing something, but cannot see what it is, so far
anyway.
| > | There are no missing references either.
| > |
| > | Thanks for any help,
| > |
| > | TomT
| > |
| > |
| >
| >
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top