Results 1 to 2 of 2
  1. #1
    TimMoffy is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    May 2012
    Posts
    29

    Export to Excel Error Handling

    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.

    Click image for larger version. 

Name:	output to.JPG 
Views:	3 
Size:	12.0 KB 
ID:	7968
    Of course everyone has got excited about this as they received a Run Time Error 2501 message.

    Click image for larger version. 

Name:	error 2501.JPG 
Views:	3 
Size:	9.8 KB 
ID:	7967
    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

  2. #2
    TimMoffy is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    May 2012
    Posts
    29
    After lots more reading I have found my own solution and begining to understand Error Handling a lot more than i did a couple of hours ago.
    Thanks for viewing anyway.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Error when trying to export from table to Excel
    By tobinjames in forum Import/Export Data
    Replies: 3
    Last Post: 12-15-2011, 02:55 PM
  2. Annoying error on macro export to excel - missing rows
    By Blueweasel in forum Import/Export Data
    Replies: 0
    Last Post: 12-15-2011, 04:41 AM
  3. Error 2501 displays with Error handling
    By agent- in forum Programming
    Replies: 13
    Last Post: 08-05-2011, 02:20 PM
  4. Macro export to excel error
    By Andy_d in forum Import/Export Data
    Replies: 7
    Last Post: 04-15-2011, 09:54 AM
  5. Export Pivot table to Excel Error
    By Whalen16 in forum Import/Export Data
    Replies: 3
    Last Post: 09-30-2010, 12:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums