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