Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 416
  • Last Modified:

CommonDialog1.CancelError = False not working

I thought that CommonDialog1.CancelError = False meant that when hitting CANCEL on on a common dialog window (instead of selecting a file to be opened) would prevent the 'Run Time Error 9' that normally happens if you don't have that line in or have it set to true. I'm still getting that error by opening a commondialog and hitting cancel instead of selecting a file. Any suggestions?
0
JohnDoeSr
Asked:
JohnDoeSr
2 Solutions
 
vinnyd79Commented:
What is the code trying to do after cancel is selected? Have you tried error handling?

Private Sub Command1_Click()
On Error GoTo ErrHandler
CommonDialog1.CancelError = True
CommonDialog1.ShowOpen


Exit Sub
ErrHandler:
If Err.Number = 32755 Then
    MsgBox "Cancel has been pressed"
End If
End Sub
0
 
Hit_MNCommented:

Run time error 9 ??
The "Cancel Error" is 20001 : in fact the typical error handler is like this:

Private Sub MyProc()

        On Error GoTo MyProc_Err

'         CODE ....

        Exit Sub

MyProc:
        If Err.Number <> 20001 Then
                ' Normal error handling here...
        End If

End Sub

So, the error 9 is not caused by the CancelError, but from something else...
Please, post your procedure for us to check.

HTH
Marco.
0
 
AzraSoundCommented:
If you do not have the cancel button raise an error, then right after your ShowOpen or whatever it is that you are calling, you need to check if a FileName was given (which it will not if the user clicked cancel) and take the appropriate steps in your code to avoid an error that may be raised due to an empty filename.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now