PDA

View Full Version : Send a data of query in a email



kbsudhir
06-02-2009, 07:06 AM
Hi All,

I have query in access 2003. I need to send the data generated by the query through email in excel format.

How to go about doing this.

:think: :think:

Any guidance is appreciated.

Regards
Sudhir

CreganTur
06-02-2009, 07:19 AM
I need to send the data generated by the query through email in excel format.


Do you mean that you need to attach an Excel workbook, or you want the data to appear in a table in the body of the email?

kbsudhir
06-03-2009, 06:35 AM
Hi Randy,

I want to attach it as an excel woorkbook.

I am able to do that. Below is the code.



Private Sub Send_Mail()

strpath = "D:\Temp Report\" + "Report" + ".xls"
DoCmd.OutputTo acOutputQuery, "Deadline_Report", acFormatXLS, strpath, False

Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)

MailOutLook.BodyFormat = olFormatHTML
MailOutLook.Attachments.Add strpath

MailOutLook.Body = "" & vbCr & _
"Hi Team" & vbCr & _
"" & vbCr & _
"Attached is the report for the mails received." & vbCr & _
""


Dim Address(3) As String
Address(0) = "imc@xyz.com"
Address(1) = "rad@xyz.com (rad@ingrammicro.ca)"
Address(2) = "efq@xyz.com (efq@ingrammicro.ca)"
Address(3) = "tms@xyz.com (tms@ingrammicro.ca)"

x = 0

Do Until x > 3

MailOutLook.Recipients.Add Address(x) & " "
x = x + 1
Loop

MailOutLook.CC = "abc@xyz.com (abc@xyz.com)"
MailOutLook.Subject = "Mail Report"

MailOutLook.Importance = olImportanceHigh
MailOutLook.Send


End Sub




But the problem is outlook security message is displayed. Is there some way to overcome this.

Thanks
Sudhir