PDA

View Full Version : Printing to non default printer


Unregistered
October 21, 2002, 15:10:34
Hi .

Any one any ideas on this one?

I'm writing a web application, that needs to print to a printer on the server, not on the client. In essence, I'm looping though the printers collection to get a printer HDC ( the printer name selected by the client), and passing the appropriate printer hdc to the TXTextControl1.PrintDevice. The printer HDC is the correct one for the printer that I need to print to.

I get the following error:

Automation error:The Object Invoked as been disconnected from its clients.

If I print to the default printer, everythings fine. If I use the MDI demo provided, and select a non default printer, I get a blank page, and the default printer is set to the printer that I selected ( wird!!)

Code-wise, my code looks identical to the example in ther help file - ok - so I've tried various orders for the lines and not joy.

I'm running Windows 2000 server, IIS and IE6, developing in VB6. I checked permissions, and everythign that needs permissions has access to everything.

Any help / comments much appreciated!

Lewin Trussler


This message was originally posted by Lewin Trussler in the old TX Text Control Support Forum.

Unregistered
October 26, 2002, 00:16:16
This is the code I use and it prints to the local as well as to a network printer.
Some of the code is relevant to my type of page only, but you should be able to use it as is with corrections to the txtextcontrol name you are using.

|;)
lee

Sub FilePrint()

Dim Copy, CurPage, StartPage, EndPage As Integer
StartPage = 1
EndPage = frmMDIParent.ActiveForm.TXTextControl1.CurrentPage s
' the next line is important
Printer.TrackDefault = False
On Error Resume Next
' Initialize and call the common print dialog
If DefaultPrtrFlag = 1 Then
frmMDIParent.CMDialog1.PrinterDefault = True
Else
frmMDIParent.CMDialog1.PrinterDefault = False
End If
frmMDIParent.CMDialog1.Copies = 1
frmMDIParent.CMDialog1.FromPage = 1
frmMDIParent.CMDialog1.ToPage = EndPage
frmMDIParent.CMDialog1.Min = 1
frmMDIParent.CMDialog1.Max = EndPage
frmMDIParent.CMDialog1.Flags = cdlPDHidePrintToFile Or cdlPDNoSelection
frmMDIParent.CMDialog1.CancelError = True
frmMDIParent.CMDialog1.ShowPrinter
If Err Then Exit Sub

' Get first and last page
If frmMDIParent.CMDialog1.Flags And cdlPDPageNums Then
StartPage = frmMDIParent.CMDialog1.FromPage
EndPage = frmMDIParent.CMDialog1.ToPage
End If

' Print selected pages

Printer.Orientation = frmMDIParent.CMDialog1.Orientation
Printer.Copies = frmMDIParent.CMDialog1.Copies
'This relates only to my page
If InStr(Printer.DeviceName, (UCase("TEC"))) Or InStr(Printer.DeviceName, (UCase("TSC"))) Then
Dim psize As Variant
psize = Printer.PaperSize
psize = Printer.Height
If Doc.lHeight > 0 Then
Printer.Height = Doc.lHeight

End If
psize = Printer.PaperSize
End If

Printer.Print
For Copy = 1 To frmMDIParent.CMDialog1.Copies
For CurPage = StartPage To EndPage
Select Case TemplateMode
Case "1x3S"
Dim wPages, No
wPages = frmMDIParent.ActiveForm.frmMDIChild.TXTextControl2 (No).CurrentPages
wPages = 1
For No = 1 To wPages
frmMDIParent.ActiveForm.frmMDIChild.TXTextControl2 (No).PrintDevice = Printer.hDC
frmMDIParent.ActiveForm.frmMDIChild.TXTextControl2 (No).PrintPage No
'Printer.NewPage
Next No
'Printer.EndDoc
frmMDIParent.ActiveForm.TXTextControl1.PrintDevice = Printer.hDC
frmMDIParent.ActiveForm.TXTextControl1.PrintPage CurPage
Dim i As Integer
'For i = 1 To MaxID

' frmMDIParent.ActiveForm.frmMDIChild.TXTextControl2 (i).PrintDevice = Printer.hDC
' frmMDIParent.ActiveForm.frmMDIChild.TXTextControl2 (i).PageMarginL = frmMDIChild.TXTextControl2(i).Left
' frmMDIParent.ActiveForm.frmMDIChild.TXTextControl2 (i).PageMarginT = frmMDIChild.TXTextControl2(i).Top
' frmMDIParent.ActiveForm.frmMDIChild.TXTextControl2 (i).PrintPage 1
' Next i
Case "", "Single"
frmMDIParent.ActiveForm.TXTextControl1.PrintDevice = Printer.hDC
frmMDIParent.ActiveForm.TXTextControl1.PrintPage CurPage
If CurPage <> EndPage Then Printer.NewPage
Case "User Defined"

frmMDIParent.ActiveForm.TXTextControl1.PrintDevice = Printer.hDC
frmMDIParent.ActiveForm.TXTextControl1.PrintPage CurPage
If CurPage <> EndPage Then Printer.NewPage
End Select
Next CurPage
Next Copy

Printer.EndDoc

End Sub


This message was originally posted by Lee Sorensen in the old TX Text Control Support Forum.