CarysW
Complete Access Numpty
- Local time
- Today, 09:13
- Joined
- Jun 1, 2009
- Messages
- 213
Hello
I have a custom dialog box which has combo boxes to choose criteria for a query and then exports the query to Excel. The problem comes if the user gets to the 'Output To' save box but then decides to cancel I/they get Run-Time Error '2501': The OutputTo Action was cancelled which then stops the procedure and efefctively for the end user breaks the database and scares the hell out of them! Is there some code I can add that will either stop them cancelling or alternativel, and preferably for VBA to just ignore it and cancel the whole action, closing the dialog box(as it is supposed to once saved) Code shown below:
I have a custom dialog box which has combo boxes to choose criteria for a query and then exports the query to Excel. The problem comes if the user gets to the 'Output To' save box but then decides to cancel I/they get Run-Time Error '2501': The OutputTo Action was cancelled which then stops the procedure and efefctively for the end user breaks the database and scares the hell out of them! Is there some code I can add that will either stop them cancelling or alternativel, and preferably for VBA to just ignore it and cancel the whole action, closing the dialog box(as it is supposed to once saved) Code shown below:
Code:
Private Sub cmdOKRepHQAll_Click()
If IsNull(cboREPAll) Then
MsgBox "You must choose a Rep." _
& vbCrLf & "Please try again.", vbExclamation, _
"More information required."
Exit Sub
End If
' Open MsgBox to tell user that a save box will open next
MsgBox "Please Rename and Save The Export", vbQuestion, "Export To Excel"
' Exports Query to Excel
DoCmd.OutputTo acOutputQuery, "qryByRep", "ExcelWorkbook(*.xlsx)", "", True, "", 0, acExportQualityPrint
' Closes Form
DoCmd.Close acForm, "frmChAllbyRep"
End Sub