Public Sub DAO_Execute()
'Database Query and Recordset Decs
Dim db As Database
Dim qdef As QueryDef
Dim rsContacts As DAO.Recordset
Dim fld As String
'Declaire Outlook and message variables/recordsets
Dim objOutlook As New Outlook.Application
Dim objEmail As Outlook.MailItem
Dim strLtrContent As String
Dim strEMailMsg As String
Dim ctlEmailBox As String
'Assigning values
ctlEmailBox = Nz(tLookup("SettingValue", "tblGlobalSettings", "SettingName = 'SpecialLetter'"), "Special Letter text not entered")
'rsContacts.ActiveConnection = CurrentProject.Connection *taken out as already done below
fld = "Assigned_To"
'Setting values
Set db = CurrentDb
Set qdef = db.QueryDefs("qryCompletedWorkRequests")
qdef.Parameters![Please enter a start date DD/MM/YYYY] = [Forms]!frmCompletedWorkRequestsFROMteamsite![Modified]
qdef.Parameters![Please enter an end date DD/MM/YYYY] = [Forms]!frmCompletedWorkRequestsFROMteamsite![Modified]
Set rsContacts = qdef.OpenRecordset(dbOpenDynaset)
Do While Not rsContacts.EOF
strLtrContent = "Dear " & rsContacts("Created_By") & "," & Chr(13) & Chr(13) & ctlEmailBox & Chr(13)
strLtrContent = strLtrContent & "You will be rating how " & rsContacts("Assigned_To")
strLtrContent = strLtrContent & " performed for the work request you submitted on " & rsContacts("Created") & "." & Chr(13)
strLtrContent = strLtrContent & "Named: '" & rsContacts("Title") & "'" & Chr(13)
strLtrContent = strLtrContent & "Please click on the link below and enter your work request ID (" & rsContacts("ID") & ") 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 & "[URL]https://teams.cokecce.com/sites/SystemsInformationBSC/Lists/Customer%20Satisfaction%20Survey/NewForm.aspx?Source=https%3A%2F%2Fteams%2Ecokecce%2Ecom%2Fsites%2FSystemsInformationBSC%2FLists%2FCustomer%2520Satisfaction%2520Survey%2Foverview%2Easpx[/URL]" & 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("Created_By")
objEmail.Subject = "Customer Satisfaction Survey BSC"
objEmail.Body = strLtrContent
objEmail.Importance = olImportanceHigh
objEmail.BodyFormat = olFormatHTML
objEmail.Display
'objEmail.Send
Debug.Print rsContacts!Assigned_To
rsContacts.MoveNext
Loop
qdef.Close
rsContacts.Close
db.Close
End Sub