Results 1 to 4 of 4

Thread: [RESOLVED] commondialog help

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2006
    Location
    Philippines
    Posts
    177

    Resolved [RESOLVED] commondialog help

    VB Code:
    1. Private Sub cmdUpload_Click()
    2.     With CommonDialog1
    3.         .FileName = "*.xls"
    4.         .Filter = "*.xls"
    5.         .ShowOpen
    6.         uploadfile = .FileName
    7.     End With
    8.     Save_BillingStatus
    9. End Sub

    how do i code if i try to open the dialogbox then i cancel the button?? it must not go to the Save_billingstatus function.. anyhelp?

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: commondialog help

    Add error handling and set the .CancelError = True.
    VB Code:
    1. Private Sub cmdUpload_Click()
    2.     With CommonDialog1
    3.         .CancelError = True
    4.         .FileName = "*.xls"
    5.         .Filter = "Excel Files Only (*.xls)|*.xls"
    6.         .ShowOpen
    7.         uploadfile = .FileName
    8.     End With
    9.     Save_BillingStatus
    10.     Exit Sub
    11. MyError:
    12.     If Err.Number <> cdlCancel Then
    13.         MsgBox Err.Number & " - " & Err.Description
    14.     End If
    15. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: commondialog help

    Something Like this:
    VB Code:
    1. Private Sub cmdUpload_Click()
    2.  
    3.     On Error GoTo errHandler
    4.     With CommonDialog1
    5.  
    6.        .Flags = cdlOFNHideReadOnly + cdlOFNOverwritePrompt + cdlOFNPathMustExist + cdlOFNNoReadOnlyReturn + cdlOFNLongNames + cdlOFNExplorer
    7.        .CancelError = True
    8.        .InitDir = DirName
    9.        .Filename = "*.xls"
    10.        .Filter = "Excel |*.xls"
    11.        .ShowOpen
    12.        uploadfile = .FileName
    13.  
    14.     End With
    15.  
    16.     Save_BillingStatus
    17.  
    18.     Exit Sub
    19.    
    20. errHandler:
    21.  
    22.     Select Case Err
    23.     Case 32755 '  Dialog Cancelled
    24.        DoEvents
    25.     Case Else
    26.        MsgBox "Unexpected error. Err " & Err & " : " & Error
    27.     End Select
    28.      
    29.     End Sub
    Last edited by randem; Jul 18th, 2006 at 10:57 PM.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: commondialog help

    Since .Showopen is a Modal call you do not need to move the Save_BillingStatus function call. If the user clicks cancel it wil bypass that line and go straight to the error handler.

    Also, you have the logic backwards for the cancel as the poster wants it so it doesnt get executed if cancel is clicked.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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