[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

SendObject  only as an attachment-need it in email body

Posted on 2013-02-07
5
Medium Priority
?
299 Views
Last Modified: 2013-03-22
I am using Access 2003 and Outlook 2010 (Cloud).  I am trying to use SendObject to write Query data results into the body of an email - not as an attachment.

Is this possible?

Thanks!
Nancy
0
Comment
Question by:NEC293
[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
  • 3
  • 2
5 Comments
 
LVL 28

Expert Comment

by:omgang
ID: 38864998
It should be possible.  You'll need to construct the message body as a string based upon the query result set.  Something like this

Dim rs As DAO.Recordset
Dim strBody As String

Set rs = CurrentDb.OpenRecordset ("MyQuery")

strBody = "Good Day.  Here's the daily report from the database:  " & vbCrLf & vbCrLf

rs.MoveFirst
Do Until rs.EOF
    strBody = strBody & rs(0) & ", " & rs(1) & ", " & rs(2) & ", " & etc. etc. & vbCrLf
    rs.MoveNext
Loop

strBody = strBody & vbCrLf & "That's it!"

    'send the report as an email msg
    'DoCmd.SendObject acSendNoObject is default, ObjectName, OutputFormat, To, CC, BCC, Subject, Body
DoCmd.SendObject , , , "TheRecipient@MyDomain.com", "ccAddress@Mydomain.com", , "Daily Report", strBody

    'destroy object variable
Set rs = Nothing



OM Gang
0
 

Author Comment

by:NEC293
ID: 38873562
I'm rather a novice at this ... the query I am running uses a date range entered by the user.
Does that make a difference in using this code?
0
 
LVL 28

Expert Comment

by:omgang
ID: 38876130
Yes.  You need to explicitly declare the parameters for the parameter query when opening a DAO recordset upon it.

How are the users entering the date range?  Prompt from the query itself or via fields/controls on a form?

OM Gang
0
 

Author Comment

by:NEC293
ID: 38877224
Prompt from the query itself.
0
 
LVL 28

Accepted Solution

by:
omgang earned 1500 total points
ID: 38877552
OK.  I'll work off the assumption your query has a criteria expression in it something like this
WHERE (((data.dDate) Between [Enter Start] And [Enter End]));

The bracketed values [Enter Start] & [Enter End] are called parameters.  We need to explicitly supply those when opening a recordset on the query object

So we make the following changes

Dim qdf As DAO.QueryDef
Dim rs As DAO.Recordset
Dim dStart As Date, dEnd As Date
Dim strBody As String

    'here we prompt the user to inpute the start and end date values.
dStart = CDate(InputBox("Enter start date"))
dEnd = CDate(InputBox("Enter end date"))

Set qdf = CurrentDb.QueryDefs("MyQuery")
qdf.Parameters("[Enter Start]" = dStart
qdf.Parameters("Enter End]") = dEnd
Set rs = qdf.OpenRecordset ("MyQuery")

strBody = "Good Day.  Here's the daily report from the database:  " & vbCrLf & vbCrLf

rs.MoveFirst
Do Until rs.EOF
    strBody = strBody & rs(0) & ", " & rs(1) & ", " & rs(2) & ", " & etc. etc. & vbCrLf
    rs.MoveNext
Loop

strBody = strBody & vbCrLf & "That's it!"

    'send the report as an email msg
    'DoCmd.SendObject acSendNoObject is default, ObjectName, OutputFormat, To, CC, BCC, Subject, Body
DoCmd.SendObject , , , "TheRecipient@MyDomain.com", "ccAddress@Mydomain.com", , "Daily Report", strBody

    'destroy object variables
Set rs = Nothing
Set qdf = Nothing



OM Gang
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

649 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