[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Error Received when SendObject command is cancelled

Posted on 2013-02-07
15
Medium Priority
?
346 Views
Last Modified: 2013-02-12
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
0
Comment
Question by:gdunn59
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 4
15 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38865581
I don't see anything wrong...

testing now...
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 38865590
I don't see anything wrong either.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38865594
your code works fine for me here...

Perhaps your report it self is not able to be opened
Database88-2013-02-07.mdb
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:gdunn59
ID: 38865698
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
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 38865746
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.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38865783
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...
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 38865852
"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
0
 
LVL 1

Author Comment

by:gdunn59
ID: 38865873
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
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 38865930
No, it would say "MISSING" in front of the missing reference if anything was missing.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38865952
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
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 38865969
Jeff,

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

Dale
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38865982
LOL
Me too...
Biceps and  Lats tonight...
0
 
LVL 1

Accepted Solution

by:
gdunn59 earned 0 total points
ID: 38866326
Everyone,

Thanks for your assistance, but none of the solutions worked.

I was able to get it to work with the following code:

Private Sub cmdEmailRpt_Click()
On Error GoTo Err_cmdEmailRpt_Click

Dim olApp As Outlook.Application
Dim olmsgNew As Object
Dim strAttach1 As String
Dim strAttachTemp As String
Dim strOutputToTemp As String

''Set Attachments from Temp Area (on C Drive)
strOutputToTemp = "C:\Windows\Temp\Audit " & "_" & InquiryNum & ".PDF"

strAttachTemp = strOutputToTemp

'''Output to Temp Area (to C Drive)
DoCmd.OutputTo acOutputReport, "rptAudit_Emails", acFormatPDF, strOutputToTemp, False

' Create the Outlook session.
Set olApp = CreateObject("Outlook.Application")
Set olmsgNew = olApp.CreateItem(olMailItem)
With olmsgNew
Set fsoAttach = CreateObject("Scripting.FileSystemObject")
If Not fsoAttach.FileExists(strAttachTemp) Then
    MsgBox "File does not exist now.", vbInformation, "File Not Found"
Else
    Set olAttachList = .Attachments.Add(strAttachTemp)
End If
    .Display
End With

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

End Sub

Open in new window



I used the OutputTo Method instead of SendObject.  

With this code, if the user exits the email without sending it prompts the user "Do you want to save changes? Yes  No  Cancel.

Works like a charm.

Thanks,
gdunn59
0
 
LVL 48

Expert Comment

by:Dale Fye
ID: 38866423
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.
0
 
LVL 1

Author Closing Comment

by:gdunn59
ID: 38879530
None of the solutions provided worked.  Finally got it to work myself.

Thanks,
gdunn59
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question