|
-
May 15th, 2003, 02:54 PM
#1
Thread Starter
New Member
Printer Error...Newbie Help
I am trying to build a component that prints a list of orders. I got the code to compile and registered the DLL, but when I run the code, I get a generic 'Printer Error' message. I tried the MS Knowledge base, but no luck.
I have very little experience in VB. In fact, this is my first component. I'm pretty handy in ASP, so I thought it wouldn't be much of a stretch to go from ASP to VB.
I want it to print to the default printer and I do not need a print preview dialog box. I basically want the user to click a button and have this thing start spitting out the orders on the printer.
ok, onto the code. I can post the whole project code if you need it. This is the class it is calling on the ASP page
Code:
Public Sub PrintPackingSlip(ByVal iVendorID)
'Print Packing Slip for Vendor
' Declare my Database vars to be used in the this sub
Dim rs As Recordset
Dim sqlTxt As String
Dim strHTML As String
'Query
sqlTxt = theQuery
'Check if Connection is open
Call CheckDBConn
'Execute the SQl Statement
Set rs = DE1.MYDB.Execute(sqlTxt)
'Begin Loop through RS
Do While Not rs.EOF
'Create HTML
strHTML = rs("order_id")
'Print Text to Page
Printer.Print strHTML
'End Page
Printer.EndDoc
'New Page
Printer.NewPage
'Move to Next Record
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
End Sub
Here is the ASP code to run it.
Code:
Set objVendor = Server.CreateObject("Vendor.VendorPrint")
objVendor.PrintPackingSlip(1) ' 1 is the vendorID
Set objVendor = Nothing
This is my first post here, so I hope I'm posting in the right place.
-
May 15th, 2003, 03:50 PM
#2
Do you get runtime error 482 "Printer Error". If so that usually means there is no printer for the current user.
Also, there probably is no need to call Printer.EndDoc every iteration of your loop.
-
May 15th, 2003, 03:57 PM
#3
Originally posted by brucevde
Do you get runtime error 482 "Printer Error". If so that usually means there is no printer for the current user.
Also, there probably is no need to call Printer.EndDoc every iteration of your loop.
1) That's what I'm thinking....
2) You do if you want each item printed on a separate page.....
My own two cents..... the component runs on the server..... it isn't going to print at the user's printer....unless they happen to be in the same room......
What you may want to do is simply create an HTML page that the user can then hit the Print button on the browser.
Aslo it looks like you are sending HTML to the printer.....which will print it as litteral text, complete with all the tags....
-
May 15th, 2003, 04:01 PM
#4
2) You do if you want each item printed on a separate page.....
Admittedly, I never use this method and so assumed that NewPage would start on a spearate page. According to the docs, EndDoc just sends everything to the printer.
-
May 16th, 2003, 01:26 PM
#5
New Member
Check the validity of the data that is being sent to the printer. Do this by creating a small loop (use a breakpoint and debug) to check the ASCII value of each character in "strHTML" to make sure there are no null or other invalid (unrecognizeable to the printer) characters which are usually at the end of all fixed length records.
If in fact this is the problem, then you will need to create a routine that will strip out (or otherwise deal with) invalid characters. This may not be a bad idea anyways. It's always good to check the validity of the data that is being processed, ...before it is processed (in this case, before its sent to the printer).
Hope this helps. Be glad to help further if needed.
-
May 22nd, 2003, 12:29 AM
#6
Member
try this one
dim Printer as Printers
========================
Think Twice when u Start or Stop.
========================
-
May 22nd, 2003, 03:50 PM
#7
Thread Starter
New Member
For some reason, I wasn't getting email notifications. weird. Anyways, thanks for the replies. I do want to print a separate page for each loop. They are going to be individual packing slips.
Secondly, the printer sends the job to the SERVER's default printer? I was looking to print client-side.
I was toying with the idea of popping up a separate window that will run the query and print OnLoad with JS. I think I might be better off going that route.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|