Discussion Locked

Using CommonDialog inVB6

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

In using CommonDialog.ShowPrinter, the dialog box to select printer will show. How will my program knows if the user hit CANCEL instead of PRINT? I tried using ON ERROR, but does not work.

Thanks in Advance

6 replies

by sl-campbell

On Error GoTo Err_Handler
CommonDialog1.CancelError = True
CommonDialog1.ShowOpen

'Code to print

ExitProceedure:
Exit Sub

Err_Handler:

Resume ExitProceedure

by madestroitsolutions

The common dialog box has a property called "CancelError". If you set this to true, the common dialog box will raise an error when they click cancel. Thay way you can know. However you must handle this error:

Sub CmdPrint_OnClick()

On error goto ErrorHandler 'Cancel error raised

CommonDialog1.showPrinter

Msgbox "Thank you for printing."

Exit sub

ErrorHandler:

'If you get here, the user has cancelled
msgbox "You pressed cancel!"

End Sub

I hope that helps, good luck!

This discussion is closed to new replies.