473,387 Members | 1,497 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,387 software developers and data experts.

Including results of a query/recordset in body of an email?

1
I have a database I've created to send out tailored reports to recipients on email. This was done using a module (which creates the outlook session etc and has all the handling info etc on it) and a form with a command button + click event with the mailbody/subject,attachment path etc on it.

Everything works fine like this and currently reports are sent in the form of an attachments to the tailor made email for each recipient. What we want to do now though is instead of having each report on an attachment, we'd like the report detail to be included in the body of the email. The purpose of the attachments is for them to be completed and sent back which isn't happening.. so if recipients could just reply to the original email (with the detail on) its much easier for all concerned. I'm sure this is possible but I'm stuck on how to achieve it.

The attachment is based on a query - which is refreshed for each email according to the recipient (and data) so I was hoping to be able to reference in code to the SQL query in the on click event. I'm assuming I need to assign it to a string maybe as a recordset and do a loop so I get all the records from the query on my email. Its the coding for it that I'm struggling with and where to put it amongst the other code already written.

Any help would be great.. I've attached a file showing what i've got - hope this helps?
Attached Files
File Type: zip Private Sub Command1.zip (7.9 KB, 548 views)
Apr 25 '10 #1
1 13514
ADezii
8,834 Expert 8TB
@JDCO
Here is the general concept:
  1. Create a Recordset based on your Query, for this demo I used the Orders Qry of the Northwind Sample Database.
  2. Loop through the Recordset and concatenate Field Values (I used 3 Fields) to a String Variable (Mailbody) inserting a Carriage Return/Line Feed after each Record.
  3. Assign the Variable (Mailbody) to the Body Property of the Instance of Outlook.
Expand|Select|Wrap|Line Numbers
  1. '************************************************************************************************
  2.  
  3. Dim MyDB As DAO.Database
  4. Dim rst As DAO.Recordset
  5.  
  6. Set MyDB = CurrentDb
  7. Set rst = MyDB.OpenRecordset("Orders Qry", dbOpenForwardOnly)
  8.  
  9. With rst
  10.   Do While Not .EOF
  11.     Mailbody = Mailbody & ![OrderID] & " | " & ![CustomerID] & " | " & ![ShippedDate] & vbCrLf
  12.       .MoveNext
  13.   Loop
  14. End With
  15.  
  16. rst.Close
  17. Set rst = Nothing
  18.  
  19. oMail.Body = Mailbody
  20.  
  21. '************************************************************************************************
Apr 25 '10 #2

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

Similar topics

3
by: Roger | last post by:
Hi: Is it possible to grab recordset even after SQL throws error, but also returns data?
2
by: P B via AccessMonster.com | last post by:
I have a list of 160,000 records with these fields: fname, lname, address, city, state, zip, dob I need to generate a list with all fields where the first initial of lname and the dob are...
0
by: The Programmer | last post by:
Assistance needed urgently! I use a Sybase Database with SQL Anywhere 9 and need to send the SQL query result as the body of the e-mail from within SQL. Here's what I have thusfar: ...
0
by: The Programmer | last post by:
Assistance needed urgently! I use a Sybase Database with SQL Anywhere 9 and need to send the SQL query result as the body of the e-mail from within SQL. Here's what I have thusfar: ...
36
by: Liam.M | last post by:
hey guys, I have one last problem to fix, and then my database is essentially done...I would therefore very much appreciate any assistance anyone would be able to provide me with. Currently I...
1
by: Jaime Leivers | last post by:
Here's a median function in access that you can call in any query. You could change this to any excel function you wanted. Most people can find the windows help file that says how to call an excel...
9
by: sajuk | last post by:
Hi, any ideas for this problem would be appreciated. - I am coding to enable me to use a receipt printer as the Access Report functionality does not give the correct working function. - I have...
3
by: jambonjamasb | last post by:
Hi I have two tables: email_tbl Data_table Data table is is used to create a Form Data_form
1
by: G. Morgan | last post by:
I don't have access to a server-side solution, so I guess Javascript is my only choice. I want to pass a bunch of form fields to an email, but unsure of how to add the multiple fields into the...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.