Link to home
Start Free TrialLog in
Avatar of clarkscott
clarkscottFlag for United States of America

asked on

URGENT!! Cancel Print Job Already in spool in VB6 using API or whatever

GRADE A for quick answer.  Windows 2000 using VB6.  A print job is submitted and I want to cancel the job in code.  What is the specific syntax to accomplish.

Scott C
Avatar of Leo Eikelman
Leo Eikelman

The syntax is:

Report.PrintOut False
Avatar of clarkscott

ASKER

I don't see this in VB documentation?????
Is there a REFERENCE file to support this?

I was expecting to see something involving an API?

Here's the situation:

Production environment.  Material is entered into database.  Upon entry, a (very expensive) bar code is printed. It's possible the computer system could be down or printer off-line.  If this is an extended period of time, the material will continue its 'journey' and the bar code will not be attached (currently it's a luxery - not mandatory).  The application sends the barcode print job to the printer automatically.  We can determine if the printer is working (a timer event checks for printer activity).  If the timer-event determines the printer is down (or other system down), we want to CANCEL the print job(s) from the que (we know the name of the print document).   We want to avoid having a dozen (or more - could be 100 jobs) print jobs waiting for an 'active' printer.  Since the material has already been passed to next process - we don't need - or want - the expensive bar code(s) printed.

We tried this:

Declare Function AbortDoc Lib "gdi32" (ByVal hdc As Long) As Long

Private Sub Command1_Click()
  AbortDoc Printer.hdc
End Sub

It didn't bomb - but it didn't cancel the job either????

Scott C.
Is this what you were looking at?

http://www.devx.com/tips/Tip/12799


Leo
ASKER CERTIFIED SOLUTION
Avatar of Leo Eikelman
Leo Eikelman

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
leikelman,

thanks for the info.... but we still cannot clear the document from the print que.
We have a test program that 'sends' a document (barcode) to the printer via a command button.
We placed 'your' code in another button to CANCEL the job.  The program does not crash but (after waiting as long as if we cancelled from the Windows Printer dialog box) the job in the que does not clear.

We could simply allow Windows to dialog-box the user informing them of a printer error... but the VB form is modal and the Windows message doesn't pop-up in front.  Therefore... the program continues to stack print jobs in the que ...and so on.

We would settle for a method of determining the NUMBER of jobs in the printer que.  We could apply logic to look for a maximum jobs and then stop the program from printing if we see too many jobs (with the assumption that too many jobs = not printing).

Scott C
Printer.Killdoc
If you are refering to something tha is already printing than I don't think you will be able to do much, you could contact your printer manufacturer and ask them if they have an escape code to cancel or stop a print job. Once you have the escape sequence codes you can call Escape API to send directly to the printer.

How To Use PASSTHROUGH Escape to Send Data Directly to Printer
http://support.microsoft.com/kb/q96795/
The print job is NOT currently printing.  We've been testing by taking the printer offline (since this is one of the reasons we want to be able to cancel all print jobs).



Scott C
It will be several hours before I return to the job and continue testing these suggestions.

Scott C
I was called to a different job and did not have a chance to test this.... will resume next week.

Scott C
I was not able to get this to work??  No errors.... just doesn't work.

I appreciate the effort trying to answer this question... the fact that there were no errors detected, but no success (I'm guessing) may have something to do with our system and specific hardware.

Thanks

Scott C
... some points for the effort!!!

Scott C