Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Common Dialog Box Error Trapping

Status
Not open for further replies.

BasicMark

Programmer
Jan 28, 2003
1
GB
I am using a CommonDialog Control to Open & Save Files but can not establish if the Cancel Button was Clicked, I have tried an ErrorHandler with an On Error GoTo, and an ErrorHandler with the On Error Resume Next statement, but if the Controls CancelError property is set to True, the program stops at the CommonDialog.ShowOpen with a message box telling me about the Error.

The Error Number = 32755 but I cant even trap it with code

'FAILED CODE
If Err.Number = 32755 Then
Cancel Was Clicked
Else
Open Was Clicked
End If

'FAILED CODE
On Error GoTo ErrorHandler
CommonDialog.ShowOpen

filename = CommonDialog.FileName

ErrorHandler:
Cancel was Clicked
Exit sub

If the Controls CancelError property is set to False, then no Errors occure, but I can not seperate the Open or Cancel operations to be handled.

Is there a way of using CommonDialog Error constants, Eg.
cdlCancel. to assume a Canceled option.

Regards MARK
 
First of all check the filename property. The dialog will not disappear if you click open and no file is selected.

This means that when the filename property of the commondialog equals vbnullstring, either the cancel button or the close button (right top cross) has been clicked.

Further more about your error: off course you cannot handle an error in an hierarchical lower routine, because the error simply does not exist (yet) in that routine. Handle the error in (one of) the parent routines. (Look for the routine that must work with the filename)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top