Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error setting active printer in word in Script task

Status
Not open for further replies.

timotai

Technical User
Apr 13, 2002
119
0
0
GB
Hi all

I am attempting to create an SSIS package that uses data from SQL Server to automatically create letters. It all works fine except for when I try to change the active printer (oWord.ActivePrinter = Default_printer). At this point I get an error. I have used the same code in a VB.net application outside of SSIS and it works fine. Does anybody know what is wrong?

Error:
[Script Component [186]] Error: System.Runtime.InteropServices.COMException (0x800A1460): There is a printer error. at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.HandleUserException(Exception e) at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.ProcessInput(Int32 inputID, PipelineBuffer buffer) at Microsoft.SqlServer.Dts.Pipeline.ManagedComponentHost.HostProcessInput(IDTSManagedComponentWrapper90 wrapper, Int32 inputID, IDTSBuffer90 pDTSBuffer, IntPtr bufferWirePacket)

[Code/]
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim oTable As Word.Table


'Start Word and open the document template.
oWord = New Word.Application
oWord.Visible = True
oDoc = oWord.Documents.Add("T:\PPM_Template.dot")

oDoc.Bookmarks.Item("Name").Range.Text = Row.Name.ToString
oDoc.Bookmarks.Item("Address1").Range.Text = Row.Address1.ToString
oDoc.Bookmarks.Item("Address2").Range.Text = Row.Address2.ToString
oDoc.Bookmarks.Item("Address3").Range.Text = Row.Address3.ToString
oDoc.Bookmarks.Item("Address4").Range.Text = Row.Address4.ToString
oDoc.Bookmarks.Item("Postcode").Range.Text = Row.Postcode.ToString
oDoc.Bookmarks.Item("Date").Range.Text = "Date: " & Today()
Dim r As Integer, rx As Integer
rx = 2 ' get count of the number of equipment items + 1 row for headers
oTable = oDoc.Tables.Add(oDoc.Bookmarks.Item("Product").Range, 1, 3)
oTable.Range.ParagraphFormat.SpaceAfter = 6
oTable.Borders.OutsideColor = Word.WdColor.wdColorBlack
oTable.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle
oTable.Borders.InsideColor = Word.WdColor.wdColorBlack
oTable.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle
oTable.Cell(1, 1).SetWidth(ColumnWidth:=250, RulerStyle:=Word.WdRulerStyle.wdAdjustNone)
oTable.Cell(1, 2).SetWidth(ColumnWidth:=100, RulerStyle:=Word.WdRulerStyle.wdAdjustNone)
oTable.Cell(1, 3).SetWidth(ColumnWidth:=100, RulerStyle:=Word.WdRulerStyle.wdAdjustNone)
oTable.Range.Tables(1).Rows.Alignment = Word.WdRowAlignment.wdAlignRowCenter
oTable.Cell(1, 1).Range.Text = "Product"
oTable.Cell(1, 2).Range.Text = "Serial Number"
oTable.Cell(1, 3).Range.Text = "Fixed Price"

For r = 2 To rx
oTable.Rows.Add()
oTable.Cell(r, 1).Range.Text = Row.Product.ToString
oTable.Cell(r, 1).Range.Font.Bold = 0
oTable.Cell(r, 2).Range.Text = Row.SerialNR.ToString
oTable.Cell(r, 2).Range.Font.Bold = 0
oTable.Cell(r, 3).Range.Text = Row.Price.ToString
oTable.Cell(r, 3).Range.Font.Bold = 0
Next
Dim Default_printer As String = "UKCA_Courtney_Service_Copier250MF_Black"
oWord.ActivePrinter = Default_printer
Try
oDoc.PrintOut(True, True)
Catch exc As Exception
Console.WriteLine(exc.Message)
End Try
[/code]

Many Thanks in advance for any replies.

Tim
 
I found the solution to my own problem. I hadn't set the Server path prior to the printername i.e. \\serverpath\printer. For some reason this didn't matter in a normal VB.net app but SSIS script task seems to want it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top