Print error from Visual Basic in Windows 2003, in the Printing forum on BrianMadden.com
Brian Madden Logo
Your independent source for desktop virtualization, consumerization, and enterprise mobility management.

Print error from Visual Basic in Windows 2003, in the Printing forum on BrianMadden.com

rated by 0 users
This post has 6 Replies | 0 Followers

Not Ranked
Points 35
Anirban Konar Posted: Fri, Jun 10 2005 6:58 AM
When trying to print a Word doc on a network printer given as \\server\sharename
from Visual Basic API, the print fails in the PrintOut() method call on the WordObject. The WordObject.ActivePrinter assignment goes through without any error (the printer is listed in the Printers collection also).

The error message is : Err.num:5140 Err.Description: Word cannot print. There is no printer installed.

The code works fine with local printer.

The same code works fine in Windows XP with network printer given as \\server\sharename.

Any ideas, why this is failing in Windows 2003 server ?
Thanks
  • | Post Points: 35
Top 10 Contributor
Points 36,234
Does this happen from a console session, or only in an ICA or RDP Session?

Does this happen when logged on as an admin, or only as a normal user?


Any errors in the event log?

Patrick Rouse

  • | Post Points: 35
Guest replied on Mon, Jun 13 2005 1:23 AM
Sir,
This happens in console session as well as RDP session. We tried logging in locally to the machine and executing the VB program and got same result.

The userid logged in is admin user.

There is no log in the event viewer for this error.

Please let me know any further queries.
Thanks,
Anirban
  • | Post Points: 5
Guest replied on Mon, Jun 13 2005 6:31 AM
Sir,
This is the Visual Basic code for your reference. I am creating a Active X exe from the same and calling it from VB form.

Public Function meth1(WordLoc As String, WordName As String, printerLoc As String, noCopies As Integer) As String
Dim I As Integer
Dim NewDoc As Object
Dim WordObject As Object
Dim printerFound As Boolean


On Error Resume Next
'MsgBox "start printing done "
Set WordObject = CreateObject("Word.Application")
If Err
Set WordObject = Nothing
meth1 = Err.Number & " " & Err.Description
Exit Function
End If

On Error Resume Next
'MsgBox "word object created "
'Open the document
Set NewDoc = WordObject.Documents.Open(WordLoc & "\\" & WordName & ".doc")

If Err
NewDoc.Close
Set WordObject = Nothing
meth1 = Err.Number & " " & Err.Description
Exit Function
End If
'MsgBox "word doc opened "

For Each objPrinter In Printers
'MsgBox ("Printer name:" & objPrinter.DeviceName)
If objPrinter.DeviceName = printerLoc Then
printerFound = True
End If
Next

If printerFound = False Then
meth1 = "Printer not found:" & printerLoc
NewDoc.Close
Set WordObject = Nothing
Exit Function
End If
'MsgBox ("Printer found:" & port & " " & driver)

'Set the printer in Word
On Error Resume Next
WordObject.ActivePrinter = printerLoc
If Err
NewDoc.Close
Set WordObject = Nothing
meth1 = "Printer found flag:" & printerFound & " " & Err.Number & " " & Err.Description
Exit Function
End If

'MsgBox ("Printer assigned:" & objPrinter.DeviceName)

On Error Resume Next
NewDoc.PrintOut False
If Err
NewDoc.Close
Set WordObject = Nothing
meth1 = "Printer found flag:" & printerFound & " " & Err.Number & " " & Err.Description
Exit Function
End If

'MsgBox ("Printed :" & objPrinter.DeviceName)
On Error Resume Next
NewDoc.Close
If Err
Set WordObject = Nothing
meth1 = Err.Number & " " & Err.Description
Exit Function
End If

'MsgBox "doc closed "
On Error Resume Next
WordObject.Quit
If Err
Set WordObject = Nothing
meth1 = Err.Number & " " & Err.Description
Exit Function
End If
meth1 = "Success"
Set WordObject = Nothing

End Function

Thanks,
Anirban.

* Please note, the same code works fine in Windows XP with network printer given as \\server\sharename.
  • | Post Points: 5
Top 75 Contributor
Points 3,220
Is the server running Windows 2K3 SP1?
  • | Post Points: 20
Guest replied on Tue, Jun 14 2005 12:33 AM
Yes, We tried with SP1 also. But same error code is returned.
  • | Post Points: 5
Guest replied on Mon, Nov 27 2006 2:41 PM
I am actually seeing this problem on an old NT machine. I am curious if anyone knows the exact cause, we have set up a printer on the NT machine and it is able to print if you open up word and print a document. It is just not recognizing the printer when the print command for word is called within VB.
  • | Post Points: 5
Page 1 of 1 (7 items) | RSS