atuljadhavnetafim
Active Member
- Joined
- Apr 7, 2012
- Messages
- 341
- Office Version
- 365
- Platform
- Windows
Hi Expert,
i am using below code to send query (GetData) result to email address mentioned below " .To = "at.jad@pol.com"", it is hard coded now.
but i need to add To and CC field from query (GetData) table result, i have three column for emails which i need to use to send email dynamically.
Email1 = use this id for .To
Email 2 = use this id for .CC
Name = use this for Subject line
i am not expert in VBA but i know this is possible, please suggest the way to send email dynamically since each customer has different email address to be use in To field and CC also different person.
Second requirement is: whatever the result come from query must be attached in Excel/PDF format in mail automatically.
Here GetData is the name of query which running fine as expected.
i am using below code to send query (GetData) result to email address mentioned below " .To = "at.jad@pol.com"", it is hard coded now.
but i need to add To and CC field from query (GetData) table result, i have three column for emails which i need to use to send email dynamically.
Email1 = use this id for .To
Email 2 = use this id for .CC
Name = use this for Subject line
i am not expert in VBA but i know this is possible, please suggest the way to send email dynamically since each customer has different email address to be use in To field and CC also different person.
Second requirement is: whatever the result come from query must be attached in Excel/PDF format in mail automatically.
Here GetData is the name of query which running fine as expected.
VBA Code:
Sub RTFBodyX()
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Dim fs, f
Dim RTFBody, strTo
Dim MyItem As Outlook.MailItem
Dim MyApp As New Outlook.Application
DoCmd.OutputTo acOutputQuery, "GetData", acFormatHTML, "GetData.htm"
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("GetData.htm", ForReading)
RTFBody = f.ReadAll
'Debug.Print RTFBody
f.Close
Set MyItem = MyApp.CreateItem(olMailItem)
With MyItem
.To = "at.jad@pol.com"
.Subject = "txtSubjectLine"
.HTMLBody = RTFBody
End With
MyItem.Send
End Sub