devxlogo

Cancel a Pending Print Job

Cancel a Pending Print Job

In the tip, “Please Stop Printing!” [“101 Tech Tips for VB Developers,” Supplement to the August 1997 issue of VBPJ, page 13], the code works fine with one exception. If you use PrintManager, anything printed before you press the Abort button is sent to the printer. This code uses the Windows API AbortDoc to prevent this. Put a button named cCancel on the form and caption it “Abort Printing.” Add this declaration to your program:

 Declare Function AbortDoc% Lib "GDI" ( _	ByVal hDC As Integer)

Add this code to the cCancel button’s Click event procedure:

 Sub cCancel_Click ()	dim i%	AbortPrintFlag=True	On Local Error Resume Next	i = AbortDoc(Printer.hDC)End Sub

Add this code to the print routine:

 AbortPrintFlag=FalseDo While ......	Printer.Print ......	DoEvents	If AbortPrintFlag then exit doLoopOn Local Error resume next  Printer.EndDoc
See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist