Debug Message when exporting to excel

Leesha
BronzeLounger
Posts: 1484
Joined: 05 Feb 2010, 22:25

Debug Message when exporting to excel

Post by Leesha »

Hi,
Is there a way to either stop the runtime message that comes up or do a custom message when someone decides not to finish the process of exporting a report to excel?

I have a database with the reports that have the option to export to excel. When someone clicks to export and the prompt comes up as to where to save, if they choose cancel they get the message "The output to was canceled". I would like to either have no message come up or something that doesn't say "runtime error 2501".

Thanks!
Leesha

User avatar
HansV
Administrator
Posts: 78241
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Debug Message when exporting to excel

Post by HansV »

I'd use an error handler along these lines:

Code: Select all

Private Sub cmdExport_Click()
    On Error GoTo ErrHandler
    ...
    ...
    Exit Sub

ErrHandler:
    If Err = 2501 Then
        ' Ignore this error
    Else
        ' Display error message
        MsgBox Err.Description, vbExclamation
    End If
End Sub
Best wishes,
Hans

Leesha
BronzeLounger
Posts: 1484
Joined: 05 Feb 2010, 22:25

Re: Debug Message when exporting to excel

Post by Leesha »

Perfect! I will give it a shot. Thanks so much!

Leesha
BronzeLounger
Posts: 1484
Joined: 05 Feb 2010, 22:25

Re: Debug Message when exporting to excel

Post by Leesha »

Hi Hans,
Finally had time to try this and it worked like a charm.
Thanks!
Leesha

User avatar
HansV
Administrator
Posts: 78241
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Debug Message when exporting to excel

Post by HansV »

Thanks for the feedback!
Best wishes,
Hans

Leesha
BronzeLounger
Posts: 1484
Joined: 05 Feb 2010, 22:25

Re: Debug Message when exporting to excel

Post by Leesha »

NP! It took me a little bit to figure out exactly where to place stuff but that was good because I taught me the rationale behind the process for future use.