CommonDialog1.CancelError = False not working

Posted on 2006-04-26
Last Modified: 2012-06-27
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?
Question by:JohnDoeSr
    LVL 28

    Expert Comment

    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

    Exit Sub
    If Err.Number = 32755 Then
        MsgBox "Cancel has been pressed"
    End If
    End Sub
    LVL 6

    Assisted Solution


    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

            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.

    LVL 28

    Accepted Solution

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Suggested Solutions

    Title # Comments Views Activity
    Detect VBA Font Colors 15 44
    Problem to delete range 4 44
    Window placement 17 55
    VBA open file from excel cell 4 29
    There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now