Results 1 to 7 of 7

Thread: Printer Error...Newbie Help

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2003
    Posts
    2

    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.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    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.

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    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....
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    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.

  5. #5
    New Member
    Join Date
    May 2003
    Location
    Detroit
    Posts
    6
    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.

  6. #6
    Member
    Join Date
    Mar 2002
    Location
    India
    Posts
    49
    try this one

    dim Printer as Printers
    ========================
    Think Twice when u Start or Stop.
    ========================

  7. #7

    Thread Starter
    New Member
    Join Date
    May 2003
    Posts
    2
    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
  •  



Click Here to Expand Forum to Full Width