dbTalk Databases Forums  

Net Work Print Question

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Net Work Print Question in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Leslie
 
Posts: n/a

Default Net Work Print Question - 07-25-2005 , 05:16 PM






I am trying to print a document to a specific network printer in DTS using an
ActiveX VB script. I found the code below in another group, however, I'm
getting a compile error when I try executing it, and I'm unsure why.
(Expected End of Statement on Line 14)

JoeO:"You use printer collection to select your desired printer as long
as that printer is in the user's system printer collection.

Dim X As Printer
For Each X In Printers
If X.DeviceName = "MyTargetPrinter" Then
' Set printer as system default.
Set Printer = X
' Stop looking for a printer.
Exit For
End If
Next

'Then print to X " -- End JoeO extract

This is the full code:

Function Main()
Main = DTSTaskExecResult_Success

' DECLARATIONS:
Dim XLPrinter as Printer
Dim XLApp
Dim XLWkb
Dim XLWkSht

'SET VARIABLES:
Set XLApp = CreateObject("Excel.Application")
XLWkb = "C:\SQLData\MSSQL\JOBS\reports\SoftSeatPlanningRep ortBAK.xls"
XLWkSht = "Shock Blocker Monthly Report"
xlapp.visible = true

'PROCESS (PRINT) WORKSHEET:
For Each XLPrinter In Printers
If XLPrinter.DeviceName = "AcctPrinter" Then
' Set printer as system default.
Set Printer = "AcctPrinter"
' Stop looking for a printer.
Exit For
End If
Next
xlapp.workbooks.open XLWkb
xlapp.activeworkbook.worksheets(XLWkSht).printout

'CLOSE AND EXIT:
xlapp.ActiveWorkbook.Saved = True
xlapp.ActiveWorkbook.Close
xlapp.quit

End Function

Thanks!
Leslie

Reply With Quote
  #2  
Old   
Leo Matter
 
Posts: n/a

Default Re: Net Work Print Question - 07-26-2005 , 02:21 AM






isn't it that
' DECLARATIONS:
Dim XLPrinter as Printer

you should comment out the as printer

"Leslie" <Leslie (AT) discussions (DOT) microsoft.com> wrote

Quote:
I am trying to print a document to a specific network printer in DTS using
an
ActiveX VB script. I found the code below in another group, however, I'm
getting a compile error when I try executing it, and I'm unsure why.
(Expected End of Statement on Line 14)

JoeO:"You use printer collection to select your desired printer as long
as that printer is in the user's system printer collection.

Dim X As Printer
For Each X In Printers
If X.DeviceName = "MyTargetPrinter" Then
' Set printer as system default.
Set Printer = X
' Stop looking for a printer.
Exit For
End If
Next

'Then print to X " -- End JoeO extract

This is the full code:

Function Main()
Main = DTSTaskExecResult_Success

' DECLARATIONS:
Dim XLPrinter as Printer
Dim XLApp
Dim XLWkb
Dim XLWkSht

'SET VARIABLES:
Set XLApp = CreateObject("Excel.Application")
XLWkb = "C:\SQLData\MSSQL\JOBS\reports\SoftSeatPlanningRep ortBAK.xls"
XLWkSht = "Shock Blocker Monthly Report"
xlapp.visible = true

'PROCESS (PRINT) WORKSHEET:
For Each XLPrinter In Printers
If XLPrinter.DeviceName = "AcctPrinter" Then
' Set printer as system default.
Set Printer = "AcctPrinter"
' Stop looking for a printer.
Exit For
End If
Next
xlapp.workbooks.open XLWkb
xlapp.activeworkbook.worksheets(XLWkSht).printout

'CLOSE AND EXIT:
xlapp.ActiveWorkbook.Saved = True
xlapp.ActiveWorkbook.Close
xlapp.quit

End Function

Thanks!
Leslie



Reply With Quote
  #3  
Old   
Leslie
 
Posts: n/a

Default Re: Net Work Print Question - 07-26-2005 , 11:04 AM



Leo,

You are correct that it is the "as printer" which is having the problem. I
was counting the active lines in the code for line number, not including
comment lines. I re-ran the code in Access' VB Debugger and it was
definitely the Dim statement having the problem. I will try removing the "as
printer" and see if I can get a clean compile.

Cheers,
Leslie

"Leo Matter" wrote:

Quote:
isn't it that
' DECLARATIONS:
Dim XLPrinter as Printer

you should comment out the as printer

"Leslie" <Leslie (AT) discussions (DOT) microsoft.com> wrote in message
news:32EDB38E-3CB7-43DF-8E19-D04B46B756D2 (AT) microsoft (DOT) com...
I am trying to print a document to a specific network printer in DTS using
an
ActiveX VB script. I found the code below in another group, however, I'm
getting a compile error when I try executing it, and I'm unsure why.
(Expected End of Statement on Line 14)

JoeO:"You use printer collection to select your desired printer as long
as that printer is in the user's system printer collection.

Dim X As Printer
For Each X In Printers
If X.DeviceName = "MyTargetPrinter" Then
' Set printer as system default.
Set Printer = X
' Stop looking for a printer.
Exit For
End If
Next

'Then print to X " -- End JoeO extract

This is the full code:

Function Main()
Main = DTSTaskExecResult_Success

' DECLARATIONS:
Dim XLPrinter as Printer
Dim XLApp
Dim XLWkb
Dim XLWkSht

'SET VARIABLES:
Set XLApp = CreateObject("Excel.Application")
XLWkb = "C:\SQLData\MSSQL\JOBS\reports\SoftSeatPlanningRep ortBAK.xls"
XLWkSht = "Shock Blocker Monthly Report"
xlapp.visible = true

'PROCESS (PRINT) WORKSHEET:
For Each XLPrinter In Printers
If XLPrinter.DeviceName = "AcctPrinter" Then
' Set printer as system default.
Set Printer = "AcctPrinter"
' Stop looking for a printer.
Exit For
End If
Next
xlapp.workbooks.open XLWkb
xlapp.activeworkbook.worksheets(XLWkSht).printout

'CLOSE AND EXIT:
xlapp.ActiveWorkbook.Saved = True
xlapp.ActiveWorkbook.Close
xlapp.quit

End Function

Thanks!
Leslie




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.