Click to See Complete Forum and Search --> : if printer is cancelled


Archie
April 18th, 2001, 09:34 AM
I was wondering if anyone knew what to add to my code so that if the user selects "cancel" instead of "print", he returns to the listbox(that's where the print items are located) with the items as they were before the print job. I think it has something to do with vbCancel, but I can't find it anywhere in my book. Thank you very much.

Private Sub mnuPrint_Click()
Dim Item As Integer

cdlPrint.ShowPrinter
Printer.NewPage

' Prints the contents of the lstShopping list box.

For Item = 0 To lstShopping.ListCount - 1
Printer.Print lstShopping.List(Item)
Next

Printer.EndDoc

Archie Kantzavelos

shree
April 18th, 2001, 09:49 AM
If you set the CancelError property of a comm dialog box, then it will give a trappable error when the user presses the Cancel button. You can trap this error to cancel the operation.


private Sub mnuPrint_Click()
Dim Item as Integer
on error Goto ErrHndlr
cdlPrint.CancelError = true
cdlPrint.ShowPrinter
on error Goto 0
Printer.NewPage

' Prints the contents of the lstShopping list box.

for Item = 0 to lstShopping.ListCount - 1
Printer.print lstShopping.List(Item)
next

Printer.EndDoc
Exit Sub
ErrHndlr:
'The user pressed cancel
End Sub

Archie
April 18th, 2001, 10:58 AM
This works great, but the only problem is that I do not see the microsoft form that allows me to select how many pages i want to print, and which printer i want to print with? Any ideas? Thank you.

Archie Kantzavelos

shree
April 18th, 2001, 11:53 AM
What do you mean by "microsoft form"?
The printer common dialog contains a combo box that allows you to select the printer, and allows you to choose whether you want to print all pages or from a certain page to another.

Archie
April 18th, 2001, 12:06 PM
Yes...but i do not get that combo box to appear...thus, I don't have the opportunity to push "cancel". Sorry for the confusion. Any idea? Thank you.

Archie Kantzavelos