PoppapumpJ
Programmer
Hi,
I have written a DLL to generate the prints of certain print outs.
The Printer to print to is supplied as a property.
Everything works fine when accessing through a VB application. However, when I run the same code in ASP, it returns the following error:
Problem getting printer information from the system. Make sure the printer is set up correctly
The DLL is housed and registered on the server and the same printer works when Accessed through a VB App.
Below is the code of the DLL:
[tt]
Public Sub DoPrint()
On Error GoTo errHandler
Dim strPrintString
Dim myPrinter
'define string to print
strPrintString = "hello Printer"
'see if the supplied printer is installed on this server
Set myPrinter = GetPrinter
'send the print string to the document
Printer.Print strPrintString
'create a barcode and where to put it
PaintCodeBar39 Printer, 100, 100, 100, 5, "*SO45874874*", True
'end the document and send it to the printer
Printer.EndDoc
GoTo xit
errHandler:
errNumber = Err.Number
errDescription = Err.Description
xit:
Exit Sub
End Sub
Private Function GetPrinter()
Dim P
'loop through installed printers to see if supplied printer is installed
For Each P In Printers
If P.DeviceName = PrintTo Then
'if installed, set printer to it and exit loop
Set Printer = P
Exit For
End If
Next
'if retrieved printer is anything other than supplied printer, than it was not installed
'this is required because the Printer object is set to the server's default
'even if the supplied printer is not installed
If Printer.DeviceName <> PrintTo Then
'raise an error
Err.Raise vbObjectError - 90, "GetPrinter", "Printer " & PrintTo & " is not installed on the server"
Exit Function
Else
'return correct printer object
Set GetPrinter = Printer
End If
End Function[/tt]
I have written a DLL to generate the prints of certain print outs.
The Printer to print to is supplied as a property.
Everything works fine when accessing through a VB application. However, when I run the same code in ASP, it returns the following error:
Problem getting printer information from the system. Make sure the printer is set up correctly
The DLL is housed and registered on the server and the same printer works when Accessed through a VB App.
Below is the code of the DLL:
[tt]
Public Sub DoPrint()
On Error GoTo errHandler
Dim strPrintString
Dim myPrinter
'define string to print
strPrintString = "hello Printer"
'see if the supplied printer is installed on this server
Set myPrinter = GetPrinter
'send the print string to the document
Printer.Print strPrintString
'create a barcode and where to put it
PaintCodeBar39 Printer, 100, 100, 100, 5, "*SO45874874*", True
'end the document and send it to the printer
Printer.EndDoc
GoTo xit
errHandler:
errNumber = Err.Number
errDescription = Err.Description
xit:
Exit Sub
End Sub
Private Function GetPrinter()
Dim P
'loop through installed printers to see if supplied printer is installed
For Each P In Printers
If P.DeviceName = PrintTo Then
'if installed, set printer to it and exit loop
Set Printer = P
Exit For
End If
Next
'if retrieved printer is anything other than supplied printer, than it was not installed
'this is required because the Printer object is set to the server's default
'even if the supplied printer is not installed
If Printer.DeviceName <> PrintTo Then
'raise an error
Err.Raise vbObjectError - 90, "GetPrinter", "Printer " & PrintTo & " is not installed on the server"
Exit Function
Else
'return correct printer object
Set GetPrinter = Printer
End If
End Function[/tt]