473,386 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Send Access report in body of Outlook email

Is there a way to insert data/information from a report into the body of an Outlook email message?

I want the VBA code to pull the data from my report, input it into the body of my email message, and then send, without using any attachments.

Thanks for any assistance!
Oct 5 '12 #1
11 33398
twinnyfo
3,653 Expert Mod 2GB
ryaan,

There are several ways to do this, but hte best is to use a recordset to pull the specific data from your database, then build the Body Text of your e-mail and then send it, using the SendObject method. There are other ways, also, but just depends on your preferences.

What have you tried so far?
Oct 5 '12 #2
Hi Twinnyfo,

I've tried the recordset, but I can't get it to work. I've got a report called "TripCSA" that contains all the data I want to include. I want to take all that data and put it in my Outlook email body.

Thanks in advance,
Ryan
Oct 5 '12 #3
twinnyfo
3,653 Expert Mod 2GB
You will need to provide examples of your report and queries underneath that report. What about the recordset could you not get to work?

You will need to provide moreinformaiton about your database and your desired result before any of us can even begin to assist you with this. Depending on your report, this could be rather simple, or rather complex.... But since we don't even know what your report looks like, or the data behind it, I can't estimate that.
Oct 5 '12 #4
Hi Twinnyfo,

My report data is gathered from a query called "qryCurrentTrip". All the information for the query is pulled from my table "tblCurrentTrip". The query ("qryCurrentTrip") filters all the data in the "Name" field which is equal to "th98". The report shows only records with "th98" in the "Name" field (usually only about 5-10 records). The report contains 5 fields: "tripNumber", "Name", "City", "State", and "Date". As of now, every time I need to send out this report, I just copy the report data and paste it in my email. But I know there has to be a way to click a "send" button and an email will generate with my report data in the body.

Thanks,
Ryan
Oct 5 '12 #5
twinnyfo
3,653 Expert Mod 2GB
What have you tried so far and what is not working about it? This should be relatively straightforward, since you neither have many rows or collumns, but the approach will always be the same.

Create a recordset in your code that pulls the data from qryCurrentTrip, and count how many records your have.

To build the e-mail body, create your headers for each field, then cycle through your records one at a time, inserting tabs between the fields for formatting purposes.

Then all you need is to designate the e-mail address(es) and subject line and you should be good to go. You will have to play with the formatting until it suits your liking, but that is an outline for how you would do it. I'll be glad to help if you come across snags, but I won't write the code for you...
Oct 5 '12 #6
zmbd
5,501 Expert Mod 4TB
ryaanmichael
Asking for full code is against site rules. However, as twinnyfo has started the quest and it's your first post... (read the FAQ) in the future the thread might be deleted.

Of Major importance... what is your email client?
If Outlook, then there are built in methods. (open access, press [F1] and search the help file for send object)
If others then you may need to use the SMTP methods.

If you are already knee-deep in code, please post it (remember to format it using the <CODE/> button) along with an explanation of any errors and what is or is not working.

In either case, there are tons of thread here in BYTES that address this very question and have some very useful code (in-fact, I just changed one of my codes to use part of one I found here! :) ) A quick use of the search will turn up the threads for you.
Oct 5 '12 #7
Hi Twinnyfo,

Thank you so much for your continued assistance. I'm not understanding this recordset thing. At first it seemed like a really simple task. Anyways, here is my non-working code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub sentRPT_Click()
  2.  
  3. Dim openTrip As Recordset
  4. ' "rptOpenTrip" references the Report I want to include in my Outlook email
  5. ' My report gathers data from my query "qryCurrentTrip" when the values in "Name" field = "th98"
  6. Set openTrip = CurrentDb.OpenRecordset("rptOpenTrip")
  7.  
  8. '***********************************
  9. Set objOutlook = CreateObject("Outlook.application")
  10. Set objEmail = objOutlook.CreateItem(olMailItem)
  11.  
  12. 'Components of Outlook Email
  13. With objEmail
  14.     .To = "TO ADDRESS"
  15.     .Subject = "Subject Test"
  16.     .HTMLBody = openTrip
  17.     .Display
  18. End With
  19. '***********************************
  20. End Sub
Oct 5 '12 #8
twinnyfo
3,653 Expert Mod 2GB
Ryaan,

Although you declared a recordset, you must also first declare the database from which the recordset will get its information. Also, when you tried to set your recordset, you simply used the report name, which is an invalid means of establishing that recordset.

If you look below, you will see that I declare my variables, and in order to create the recordset, I must write a short SQL query that will pull data from the database (line 12) using your query as the source.

I begin bulding the E-mail content in line 15, in which you may add whatever text you want. The vbCrLf's are line feeds, so you don't have one huge block of text. You will have to play with the spacing of lines 16-17 to enable them to match up with your fields.

In lines 19-25, we are putting the content of your report (not the report itself, but the data behind it) into the e-mail body. The "Chr(9)" is to insert a [Tab] character to align the columns. In between lines 26 and 27 you could also add some more text, like your signature block or contact information.

I have always preferred to use the DoCmd.SendObject Method, because it's very easy to use (even though we are not sending an object). I know there are some other featurees of creating an Outlook Object which may be helpful, but in this particular case, it does not seem necessary to create those objects.

I hope this helps to get you closer to your goal.....

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub sentRPT_Click()
  5. On Error GoTo EH
  6.     'Recordset variables
  7.     Dim db As Database
  8.     Dim rstOpenTrip As Recordset
  9.     Dim strSQL As String
  10.     Dim strSubject, strBody, strAddresses As String
  11.     Set db = CurrentDb()
  12.     strSQL = "SELECT * FROM qryCurrentTrip;"
  13.     Set rstOpenTrip = db.OpenRecordset(strSQL, dbOpenDynaset)
  14.     If Not rstOpenTrip.EOF Then
  15.         strBody = "blah blah blah" & vbCrLf & vbCrLf
  16.         strBody = strBody & "NAME     Field2    Field3 ....etc." & vbCrLf
  17.         strBody = strBody & "==================================" & vbCrLf
  18.         rstOpenTrip.MoveFirst
  19.         Do While Not rstOpenTrip.EOF
  20.             strBody = strBody & rstOpenTrip("Name") & Chr(9) & _
  21.                 rstOpenTrip("Field2") & Chr(9) & _
  22.                 rstOpenTrip("Field3") & Chr(9) & _
  23.                 rstOpenTrip("etc.") & vbCrLf
  24.             rstOpenTrip.MoveNext
  25.         Loop
  26.     End If
  27.     strSubject = "Here's my report!"
  28.     strAddresses = "supercoder@bytes.com"
  29.     DoCmd.SendObject acSendNoObject, , acFormatTXT, strAddresses, , , strSubject, strBody, True
  30.     Exit Sub
  31. EH:
  32.     MsgBox Err.Number & " " & Err.Description
  33.     Exit Sub
  34. End Sub
Oct 5 '12 #9
Thank you so much for your time! I am going to try this out and let you know how it goes.

Thanks again,
Ryan
Oct 5 '12 #10
Twinnyfo,

Just wanted to say thank you and let you know the code works perfectly! Thanks again for your help!
Oct 9 '12 #11
twinnyfo
3,653 Expert Mod 2GB
Ryaan,

My pleasure. Glad I could help!
Oct 9 '12 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Chuck Farah | last post by:
I am unsuccessfullly trying to display an outlook email from a vb web forms (.net) outlook 2002 #1. is it possible to use outlook client email from a web form using the outlook object model...
1
by: Brian | last post by:
I have a project that I built that takes data from a recordset and then send an email to appropriate person. This process is using Access 2K and Outlook 2K. The email is going out as a RTF email...
1
by: joshua | last post by:
Is there a way to set the FROM name (the name the recepient sees as the one who sent the email) when using Access to create an Outlook email message? (Using MS-Office 2000 SP3) We set up an...
0
by: VP | last post by:
g'day, i am posting a problem i have encountered with creating an email using outlook through some basic c# code. the problem arises when using different email editors in outlook. At the moment...
8
by: tymperance | last post by:
I have a report that I currently email directly from Access as an attachment using a macro. I need to make it be the body of the email instead. Can that be accomplished without extensive VBA...
3
by: Robert S | last post by:
A friend is thrying to send me an Access database attached to an email. I am using Outlook but when the email arrives the attachemnt is missing. Any suggestions, please? When changed to Excel it...
5
AllusiveKitten
by: AllusiveKitten | last post by:
Hi All I was just wondering if it was possible to send a report as the email body. I am wanting to send an automatic email to multiple people which will be personalised with their names etc. ...
10
by: Dan2kx | last post by:
Hello to all, i have a new interesting problem to solve.... i have a report that i would like to email to a list of users, the report is a full page document and is personalised to each user...
1
by: shalskedar | last post by:
My Query is Can we create an exe file specifically for Ms Access Report because In my Database(Acess 2003)I need to send 1 of the Report as an attachment via Ms Outlook. If I try to send this...
10
by: neelsfer | last post by:
i would like to send a specific report "RaceresultsR", to the email addresses listed in a query called Rt_EmailQ and the field name in query is called "Email" The code below only show a blank "To"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.