Avatar of dawber39
Flag for United States of America asked on

EmailDatabaseObject "Multiple Reports"

I have this code within a module that emails specific reports to client. The code calls a function that opens up Outlook, calls a wait function and waits 20 seconds for Outlook to send/receive. It then sends an email with one report, waits 3 seconds, then another, and another, and Outlook does an automatic send/receive before exiting. The problem is all these emails are going to the same person.

What I would like to do is make it so that all three reports, are sent in the same email. I have tried various combinations of the code and they all fail. This is the code that sends the emails:

    WaitSeconds (20)
    DoCmd.SendObject acReport, "CustStmt", "PDFFormat(*.pdf)", "rick@kilduff.com", "", "", "CustStmt", "", False, ""

    WaitSeconds (3)

    DoCmd.SendObject acReport, "CustAdjmts", "PDFFormat(*.pdf)", "rick@kilduff.com", "", "", "CustAdjmts", "", False, ""

    WaitSeconds (3)

    DoCmd.SendObject acReport, "CustStmt Summary (Roche)", "PDFFormat(*.pdf)", "rick@kilduff.com", "", "", "CustStmt Summary (Roche)", "", False, ""

Any help would be greatly appreciated
Microsoft Access

Avatar of undefined
Last Comment

8/22/2022 - Mon
Jim Dettman (EE MVE)

SendObject simply can't do that, so you'll need to find another way to send e-mails.  There are a couple of basic methods:

1. Use a command line utility such as BLAT.

2. Use software that talks directly to a e-mail server (SMTP) such as vbSendMail

3. Using OLE automation, talk to Outlook and have it send the e-mail.

 All three of the above will allow for multiple attachments in a single e-mail.  However with that said, that's the other piece of this; you need to run and save the reports to disk first in some format (PDF, Snapshot, etc) before you can send as a single e-mail.

Jim Dettman (EE MVE)

You might also want to consider commercial software, such as FMS, inc's Total Access Mailer.

Jeffrey Coachman

Not sure, but you may be able to do this is you instantiate Outlook, using this fairly common code:

You would probably need to change the top to this:

    Sub SendMessage(DisplayMsg As Boolean)

...and change the "Add Attachment" section to something like this:
             ' Add attachments to the message.
                      Set objOutlookAttach = .Attachments.Add(AttachmentPath1)
                      Set objOutlookAttach = .Attachments.Add(AttachmentPath2)
                      Set objOutlookAttach = .Attachments.Add(AttachmentPath3)

(I am not quite sure why your "Delays" are needed though...)

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.

I cleaned that up from working code and tested it.
There are, looking at now, some extraneous declarations and comments in it
Luke Chung

Hi Jim, Thanks for mentioning Total Access Emailer:

It is a Microsoft Access add-in that lets you automatically attach multiple filtered reports as PDF to a message. You can also compress all your attachments into a zip file. The zip file can also be password protected using your phrase or a value from a field in your datasource.

Total Access Emailer also has a programmatic interface to send emails from VBA. A free trial version is available. It uses SMTP to send emails, so it bypasses all the Outlook and MAPI security limitations. Free trial here: http://www.fmsinc.com/MicrosoftAccess/Email/free-trial.html

Here's a paper we wrote entitled: DoCmd SendObject Command in Microsoft Access: Features and Limitations for Sending Emails

Haven't tried it yet - but the sample works - had shoulder surgery, and everything is on hold for now - thank you all
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.