Link to home
Start Free TrialLog in
Avatar of gdunn59
gdunn59

asked on

Error Received when SendObject command is cancelled

I have the following code behind a button on a form that a user clicks on to email the information on the screen via a report.  It creates the info in a PDF format, opens outlook and attaches the PDF.  

The problem I am having is if a user closes/cancels the email without sending they get a "2501" error.  I don't want this error or the pop-up for this error to appear.  I just want it to close/cancel the email and go back to the form again.

Here is my code:

Private Sub cmdEmailRpt_Click()
On Error GoTo Err_cmdEmailRpt_Click

Dim stDocName As String

'DoCmd.Echo False

stDocName = "rptAudit_Emails"

DoCmd.SendObject acReport, stDocName, acFormatPDF

'DoCmd.Echo True

Exit_cmdEmailRpt_Click:
    Exit Sub

Err_cmdEmailRpt_Click:
    'If the user closes the Email screen without sending.
    If Err.Number = 2501 Then
        Resume Exit_cmdEmailRpt_Click
    End If

Open in new window



What am I doing wrong?

Thanks,

gdunn59
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

I don't see anything wrong...

testing now...
I don't see anything wrong either.
your code works fine for me here...

Perhaps your report it self is not able to be opened
Database88-2013-02-07.mdb
Avatar of gdunn59
gdunn59

ASKER

boag2000:

Weird, I just tried your sample database, and the same thing happens.  I get the 2501 error.

Could it be the version of Access and/or Outlook that I am using?

I am using 2007.

Thanks,
gdunn59
No points, please!

Have you checked to make sure all of your references are there, none are "Missing"?

You might want to compact and repair your database, after making a backup.

You might also consider creating a new database and importing all of the objects from the current database into it.
Hmmm....
I just tested it in Acc 2010 and got the error

(I had tested it first in Acc 2007 with no error)

Follow up with fyed then...

I may not have time to dig further...
"Could it be the version of Access"

It might be, but as I mentioned above, it is more likely that you are missing a reference or simply have a corrupt database.  Try my recommendations (above) and see whether that fixes it.

You may also want to consider "repairing" you Access installation.  NOTE: this may require a copy of your Office installation disk

Start -> Programs -> Control Panel -> Programs -> Uninstall

Then select Office and Repair
Avatar of gdunn59

ASKER

fyed:

I've attached a screen shot of the References that I am using.  Is anything missing?

Thanks,
gdunn
Screen-Shot-of-References--for-A.docx
No, it would say "MISSING" in front of the missing reference if anything was missing.
fyed.

I'm on my way home...
I'll let you take this from here

I am sure this is something simple...

I am curious/stumped as well...

;-)

Jeff
Jeff,

I'm heading to the gym in about 10 minutes.  Home about 7PM ET, will investigate further then.

Dale
LOL
Me too...
Biceps and  Lats tonight...
ASKER CERTIFIED SOLUTION
Avatar of gdunn59
gdunn59

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry we couldn't help, but glad you found another solution.  I'm gonna try Jeff's code on my 2010 machine and see if it breaks there.
Avatar of gdunn59

ASKER

None of the solutions provided worked.  Finally got it to work myself.

Thanks,
gdunn59