I have a command button that exports data from a main table out to Excel. Don't know why as the application is full of reports, but its what the user wants.
Everything works well until a user clicked the "cancel" button on the Output dialogue box where you can choose the file name and location.
Of course everyone has got excited about this as they received a Run Time Error 2501 message.
I have no experience of Error Handling and have always used Macros to catch these for me before, but I'm trying to get to a totally VBA world.
If this is my export code below, what can i put in and where, to ignore everything if the user clicks cancel instead of OK?
I'm happy that if they chose Cancel then the whole operation stops and the output dialogue box just closes.
As always many thanks in advance for your help
Code:
Private Sub cmdFNOlExcel_Click()
'********************************
'Outputs FNOL Data Store to Excel
'********************************
DoCmd.OutputTo acOutputTable, "tblFNOLDataStore", "Excel97-Excel2003Workbook(*.xls)", "", False, "", , acExportQualityPrint
End Sub