the OutputTo Action Was Cancelled, runtime error 2501

G

Guest

I'm using the OutputTo method to export the results of a query to Excel, and
it is working fine so long as the user does not cancel the action when the
filename dialog box displays, at which point an error occurs.

This is what I wrote to ouput the results to Excel:
DoCmd.OutputTo acOutputReport, Me.Export2ExcelList, acFormatXLS, , True

My question is: how can i stop the runtime error?
 
T

tina

you need to include error handling code in the procedure, such as

On Error GoTo Handle_Err

DoCmd.OutputTo acOutputReport, _
Me.Export2ExcelList, acFormatXLS, , True

Exit_Err:
Exit Sub

Handle_Err:
Select Case Err.Number
Case 2501
' The OutputTo action was cancelled.
Resume Exit_Err
Case Else
Msgbox Err.Number & " " & Err.Description
Resume Exit_Err
End Select

hth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top