Design by Sue
Registered User.
- Local time
- Today, 01:57
- Joined
- Jul 16, 2010
- Messages
- 816
I am using the following function found on the web to open a browser window to allow the user to select the location for a download of an excel file. All is working correctly EXCEPT if the user clicks the cancel button on the browser window the code that follows runs anyway. How can I cancel the following code if the cancel button is selected in the browser window?
Public Function GetFolderName(Optional OpenAt As String) As String
Dim lCount As Long
GetFolderName = vbNullString
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = OpenAt
.Show
For lCount = 1 To .SelectedItems.Count
GetFolderName = .SelectedItems(lCount)
Next lCount
End With
End Function
Private Sub ExportExcel_Click()
GetFolderName
DoCmd.OutputTo acOutputReport, "SOP30DayRPT", acFormatXLS, "SOP30DayRPT - " & Format(Date, "mmddyyyy") & ".xls"
End Sub
The screenshot shows the cancel button in the browser window that I am talking about.
Public Function GetFolderName(Optional OpenAt As String) As String
Dim lCount As Long
GetFolderName = vbNullString
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = OpenAt
.Show
For lCount = 1 To .SelectedItems.Count
GetFolderName = .SelectedItems(lCount)
Next lCount
End With
End Function
Private Sub ExportExcel_Click()
GetFolderName
DoCmd.OutputTo acOutputReport, "SOP30DayRPT", acFormatXLS, "SOP30DayRPT - " & Format(Date, "mmddyyyy") & ".xls"
End Sub
The screenshot shows the cancel button in the browser window that I am talking about.