Results 1 to 5 of 5

Thread: common dialog boxes

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Location
    UK
    Posts
    164
    How do you detect whether the user pressed cancel when using common dialog boxes?

    Alex

  2. #2
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471

    cancel error

    It's a property of the common dialog called 'Cancel Error'.
    When this is set to true, an error is generated (32755 to be exact) and your program can execute code based on this error or you can set it to false and have your program do absolutely nothing.

  3. #3
    Guest
    You should use the On Error Statement and With statement.

    Code:
    Private Sub ..._...()
    On Error Goto User_Cancelled
    With CommonDialog1
    'do whatever
    End With
    Exit Sub
    User_Cancelled:
    Msgbox "User cancelled!", 16
    End Sub

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Location
    UK
    Posts
    164
    Thanks people, just seems strange that you have to check for an error rather than there being a way to check the cancel property of the common dialogue box e.g something like

    if (commonDialog1.cancel=true) then exit sub

    Thanks,

    Alex

  5. #5
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    You do have to set it to true.
    Missing from Matthew's code.

    Code:
    Private Sub Form_Load()
    'display the commondialog show open
    On Error GoTo errhandle:
    
        CommonDialog1.InitDir = "C:\"          'set dir path
        CommonDialog1.CancelError = True               'used in cancel code
        CommonDialog1.Filter = "All files(*.*)|*.*"    'filter for all files
        CommonDialog1.ShowOpen                         'show files
    'Extracts Filename only
    MsgBox Mid(CommonDialog1.FileName, InStrRev(CommonDialog1.FileName, "\") + 1)
    
    'Extracts File Path only
    MsgBox Left(CommonDialog1.FileName, InStrRev(CommonDialog1.FileName, "\") - 1)
    Exit Sub
    errhandle:
    
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width