|
-
Jul 18th, 2006, 10:40 PM
#1
Thread Starter
Addicted Member
[RESOLVED] commondialog help
VB Code:
Private Sub cmdUpload_Click()
With CommonDialog1
.FileName = "*.xls"
.Filter = "*.xls"
.ShowOpen
uploadfile = .FileName
End With
Save_BillingStatus
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?
-
Jul 18th, 2006, 10:50 PM
#2
Re: commondialog help
Add error handling and set the .CancelError = True.
VB Code:
Private Sub cmdUpload_Click()
With CommonDialog1
.CancelError = True
.FileName = "*.xls"
.Filter = "Excel Files Only (*.xls)|*.xls"
.ShowOpen
uploadfile = .FileName
End With
Save_BillingStatus
Exit Sub
MyError:
If Err.Number <> cdlCancel Then
MsgBox Err.Number & " - " & Err.Description
End If
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Jul 18th, 2006, 10:53 PM
#3
Re: commondialog help
Something Like this:
VB Code:
Private Sub cmdUpload_Click()
On Error GoTo errHandler
With CommonDialog1
.Flags = cdlOFNHideReadOnly + cdlOFNOverwritePrompt + cdlOFNPathMustExist + cdlOFNNoReadOnlyReturn + cdlOFNLongNames + cdlOFNExplorer
.CancelError = True
.InitDir = DirName
.Filename = "*.xls"
.Filter = "Excel |*.xls"
.ShowOpen
uploadfile = .FileName
End With
Save_BillingStatus
Exit Sub
errHandler:
Select Case Err
Case 32755 ' Dialog Cancelled
DoEvents
Case Else
MsgBox "Unexpected error. Err " & Err & " : " & Error
End Select
End Sub
Last edited by randem; Jul 18th, 2006 at 10:57 PM.
-
Jul 18th, 2006, 10:58 PM
#4
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|