DonnaCulff
Registered User.
- Local time
- Today, 13:14
- Joined
- Aug 25, 2009
- Messages
- 30
Good afternoon everyone ,
I hope you can help?
I am trying to generate emails based on a date on a form.
I have created a VBA module, connected to a recordset, generated emails to be sent depending on that recordset with a table successfully.
I want to change this so it only sends for a date range / date entered by the user now though and not loop through the entire table...hope that makes sence?
This is what I have come up with far...
----------MyCode-----------------------------------
Public Sub ControlOutlook()
Dim objOutlook As New Outlook.Application
Dim objEmail As Outlook.MailItem
Dim strLtrContent As String
Dim strEMailMsg As String
Dim rsContacts As New ADODB.Recordset
Dim ctlEmailBox As String
ctlEmailBox = Nz(tLookup("SettingValue", "tblGlobalSettings", "SettingName = 'SpecialLetter'"), "Special Letter text not entered")
rsContacts.ActiveConnection = CurrentProject.Connection
strSQL = "SELECT qryCompletedWorkRequests.*, qryCompletedWorkRequests.Date" & _
" FROM qryCompletedWorkRequests" & _
" WHERE (((qryCompletedWorkRequests.Date)=Forms!frmCompletedWorkRequestsFROMteamsite!Modified));"
rsContacts.Open "strSQL"
'previous tries...please ignore
'rsContacts.Open "qryCompletedWorkRequests"
'rsContacts.Open "SELECT * FROM tblWorkRequests WHERE Forms![frmCompletedWorkRequestsFROMteamsite]![Modified] = Date.Value;"
'Set cmd.ActiveConnection = _
' CurrentProject.Connection
'cmd.CommandText = "qryCompletedWorkRequests"
'Set rsContacts = cmd.Execute(, _
'Array(Forms!frmCompletedWorkRequestsFROMteamsite!Date.Value), _
adCmdStoredProc)
Do While Not rsContacts.EOF
strLtrContent = "Dear " & rsContacts("Requestor") & "," & Chr(13) & Chr(13) & ctlEmailBox & Chr(13)
strLtrContent = strLtrContent & "You will be rating how " & rsContacts("AnalystName")
strLtrContent = strLtrContent & " performed for the work request you submitted on " & rsContacts("DateOfRequest") & "." & Chr(13)
strLtrContent = strLtrContent & "Named: '" & rsContacts("WorkRequestTitle") & "'" & Chr(13)
strLtrContent = strLtrContent & "Please click on the link below and enter your work request ID (" & rsContacts("WorkRequestID") & ") to begin. Complete all answers and press the 'Finish' button to complete." & Chr(13)
strLtrContent = strLtrContent & "Thank you for your time." & Chr(13)
strLtrContent = strLtrContent & "https://teams.cokecce.com/sites/Sys...ustomer%20Satisfaction%20Survey/overview.aspx" & Chr(13) & Chr(13)
strLtrContent = strLtrContent & "The content of this email is the confidential property of Coca-Cola Enterprises and should not be copied, modified, retransmitted, or used for any purpose except with written authorization. If you are not the intended recipient, please delete all copies and notify us immediately. " & Chr(13) & Chr(13) & _
"Coca-Cola Enterprises Limited - Registered in England: Company Number 27173 - Registered Office: Charter Place, Vine Street, Uxbridge UB8 1EZ" & Chr(13)
Set objEmail = objOutlook.CreateItem(olMailItem)
objEmail.Recipients.Add rsContacts("Requestor")
objEmail.Subject = "Customer Satisfaction Survey BSC"
objEmail.Body = strLtrContent
objEmail.Importance = olImportanceHigh
objEmail.BodyFormat = olFormatHTML
objEmail.Display
'objEmail.Send
rsContacts.MoveNext
Loop
End Sub
I hope you can help?
I am trying to generate emails based on a date on a form.
I have created a VBA module, connected to a recordset, generated emails to be sent depending on that recordset with a table successfully.
I want to change this so it only sends for a date range / date entered by the user now though and not loop through the entire table...hope that makes sence?
This is what I have come up with far...
----------MyCode-----------------------------------
Public Sub ControlOutlook()
Dim objOutlook As New Outlook.Application
Dim objEmail As Outlook.MailItem
Dim strLtrContent As String
Dim strEMailMsg As String
Dim rsContacts As New ADODB.Recordset
Dim ctlEmailBox As String
ctlEmailBox = Nz(tLookup("SettingValue", "tblGlobalSettings", "SettingName = 'SpecialLetter'"), "Special Letter text not entered")
rsContacts.ActiveConnection = CurrentProject.Connection
strSQL = "SELECT qryCompletedWorkRequests.*, qryCompletedWorkRequests.Date" & _
" FROM qryCompletedWorkRequests" & _
" WHERE (((qryCompletedWorkRequests.Date)=Forms!frmCompletedWorkRequestsFROMteamsite!Modified));"
rsContacts.Open "strSQL"
'previous tries...please ignore
'rsContacts.Open "qryCompletedWorkRequests"
'rsContacts.Open "SELECT * FROM tblWorkRequests WHERE Forms![frmCompletedWorkRequestsFROMteamsite]![Modified] = Date.Value;"
'Set cmd.ActiveConnection = _
' CurrentProject.Connection
'cmd.CommandText = "qryCompletedWorkRequests"
'Set rsContacts = cmd.Execute(, _
'Array(Forms!frmCompletedWorkRequestsFROMteamsite!Date.Value), _
adCmdStoredProc)
Do While Not rsContacts.EOF
strLtrContent = "Dear " & rsContacts("Requestor") & "," & Chr(13) & Chr(13) & ctlEmailBox & Chr(13)
strLtrContent = strLtrContent & "You will be rating how " & rsContacts("AnalystName")
strLtrContent = strLtrContent & " performed for the work request you submitted on " & rsContacts("DateOfRequest") & "." & Chr(13)
strLtrContent = strLtrContent & "Named: '" & rsContacts("WorkRequestTitle") & "'" & Chr(13)
strLtrContent = strLtrContent & "Please click on the link below and enter your work request ID (" & rsContacts("WorkRequestID") & ") to begin. Complete all answers and press the 'Finish' button to complete." & Chr(13)
strLtrContent = strLtrContent & "Thank you for your time." & Chr(13)
strLtrContent = strLtrContent & "https://teams.cokecce.com/sites/Sys...ustomer%20Satisfaction%20Survey/overview.aspx" & Chr(13) & Chr(13)
strLtrContent = strLtrContent & "The content of this email is the confidential property of Coca-Cola Enterprises and should not be copied, modified, retransmitted, or used for any purpose except with written authorization. If you are not the intended recipient, please delete all copies and notify us immediately. " & Chr(13) & Chr(13) & _
"Coca-Cola Enterprises Limited - Registered in England: Company Number 27173 - Registered Office: Charter Place, Vine Street, Uxbridge UB8 1EZ" & Chr(13)
Set objEmail = objOutlook.CreateItem(olMailItem)
objEmail.Recipients.Add rsContacts("Requestor")
objEmail.Subject = "Customer Satisfaction Survey BSC"
objEmail.Body = strLtrContent
objEmail.Importance = olImportanceHigh
objEmail.BodyFormat = olFormatHTML
objEmail.Display
'objEmail.Send
rsContacts.MoveNext
Loop
End Sub