Automatic email remainder based on due date in ms access

%3CLINGO-SUB%20id%3D%22lingo-sub-2009182%22%20slang%3D%22en-US%22%3EAutomatic%20email%20remainder%20based%20on%20due%20date%20in%20ms%20access%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2009182%22%20slang%3D%22en-US%22%3EI%20have%20a%20table%20with%20Tasks%20and%20due%20date.%20I%20would%20like%20to%20send%20automatic%20email%20remainders%20to%20the%20employees%20before%2010%20days%20for%20completion%20of%20due%20date.%20I%20am%20using%20ms%20access%202016%20version%20how%20can%20i%20do%20it.%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2009182%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAccess%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2009475%22%20slang%3D%22en-US%22%3ERe%3A%20Automatic%20email%20remainder%20based%20on%20due%20date%20in%20ms%20access%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2009475%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F909325%22%20target%3D%22_blank%22%3E%40Ramanareddy212798%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThere%20are%20several%20components%20to%20this%20task%20including%3A%3C%2FP%3E%3CUL%3E%3CLI%3EA%20way%20to%20select%20the%20tasks%20due%20in%20exactly%2010%20days%3C%2FLI%3E%3CLI%3EA%20way%20to%20select%20the%20email%20addresses%20for%20the%20employees%20assigned%20to%20those%20tasks%3C%2FLI%3E%3CLI%3EA%20way%20to%20compose%20and%20send%20the%20email%20notices.%3C%2FLI%3E%3C%2FUL%3E%3CP%3EThe%20way%20to%20put%20that%20all%20together%20depends%2C%20in%20part%2C%20on%20how%20your%20tables%20are%20designed%2C%20and%20also%20on%20how%20you%20want%20to%20trigger%20this%20process.%20It%20also%20depends%20on%20what%20email%20client%20your%20organization%20uses.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20is%20going%20to%20have%20to%20be%20a%20generic%20description%20since%20we%20don't%20have%20those%20details%20from%20you%20yet.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWrite%20a%20query%20that%20selects%20tasks%20from%20the%20task%20table.%3C%2FP%3E%3CP%3E%3CBR%20%2F%3ESelect%20TaskID%2C%20TaskName%2C%20TaskDueDate%2C%26nbsp%3B%20EmployeeFirstName%20%26amp%3B%20%22%20%22%20%26amp%3B%26nbsp%3BEmployeeLastName%20AS%20AssignedEmployee%3C%2FP%3E%3CP%3EFROM%20tblTask%20INNER%20JOIN%20tblEmployee%20On%20TblTask.AssignedEmployeeID%20%3D%20tblEmployee.EmployeeID%3C%2FP%3E%3CP%3EWHERE%20tblTask.TaskDueDate%20%3D%20DateAdd(%22D%22%2C10%2CDate)%20AND%20tblTask.TaskCompleteDate%20is%20Null%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENotice%20the%20WHERE%20clause.%20It%20assumes%20that%20you%20do%20not%20want%20to%20send%20reminders%20for%20tasks%20that%20have%20already%20been%20completed%20ahead%20of%20the%20due%20date%20and%20that%20you%20will%20do%20this%20every%20day%2C%20including%20weekends.%20If%20your%20organization%20doesn't%20want%20to%20include%20weekends%2C%20the%20process%20gets%20more%20complicated%2C%20of%20course.%3C%2FP%3E%3CP%3EYou'll%20want%20to%20set%20up%20some%20method%20of%20triggering%20this%20process%2C%20which%20can%20be%20a%20command%20button%20on%20a%20form%20that%20a%20supervisor%20clicks%2C%20or%20an%20automatic%20process%20that%20runs%20when%20the%20accdb%20is%20opened%20every%20day%20or%20some%20other%20event%20occurs....%3C%2FP%3E%3CP%3EYou%20will%20also%20need%20a%20VBA%20function%20to%20loop%20through%20the%20recordset%20generated%20by%20this%20query%20and%20send%20an%20email%20message%20to%20the%20employees%20selected.%3CBR%20%2F%3E%3CBR%20%2F%3EHere's%20a%20template%20that%20you%20can%20modify%20to%20your%20situation.%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EPrivate%20Sub%20SendEmailReminder()%3C%2FP%3E%3CP%3EDim%20varX%20As%20Variant%3CBR%20%2F%3EDim%20rstEmailList%20As%20DAO.Recordset%3CBR%20%2F%3EDim%20db%20As%20DAO.Database%3CBR%20%2F%3EDim%20strSQL%20As%20String%3CBR%20%2F%3EDim%20strReminder%20As%20String%3CBR%20%2F%3EDim%20strEmployeeName%20As%20String%3CBR%20%2F%3EDim%20strReminderText%20As%20String%3CBR%20%2F%3EDim%20strToAddress%20as%20String%3CBR%20%2F%3EDim%20lngTaskID%20As%20Long%3CBR%20%2F%3EDim%20lngprogramID%20As%20Long%3C%2FP%3E%3CP%3EOn%20Error%20GoTo%20errHandler%3CBR%20%2F%3E%3CBR%20%2F%3EvarX%20%3D%20SysCmd(acSysCmdInitMeter%2C%20%22Please%20wait%20while%20the%20email%20list%20is%20prepared%20and%20sent...%22%2C%200)%3CBR%20%2F%3ESet%20db%20%3D%20CurrentDb%3CBR%20%2F%3ESet%20rstEmailList%20%3D%20db.OpenRecordset(Name%3A%3D%22qryTaskDueDate10DayReminder%22%2C%20options%3A%3DdbOpenDynaset)%3CBR%20%2F%3E%3CBR%20%2F%3EWith%20rstEmailList%3CBR%20%2F%3EDo%20While%20Not%20.EOF%3CBR%20%2F%3EstrReminder%20%3D%20vbNullString%3CBR%20%2F%3ElngTaskID%20%3D%20!%5BTaskID%5D%3CBR%20%2F%3EstrEmployeeName%20%3D%20!AssignedEmployee%3CBR%20%2F%3EstrReminderText%20%3D%20%22Your%20Assigned%20Task%2C%20%22%20%26amp%3B%20!TaskName%20%26amp%3B%20%22%2C%20is%20due%20in%2010%20days.%22%3CBR%20%2F%3EstrToAddress%20%3D%20!%5BEmailAddress%5D%3CBR%20%2F%3ECall%20modEmail.EmailReminder(%20_%3CBR%20%2F%3EstrReminder%3A%3DstrReminder%2C%20_%3CBR%20%2F%3ERecipient%3A%3DstrEmployeeName%2C%20_%3CBR%20%2F%3EToAddress%3A%3DstrToAddress%2C%20_%3CBR%20%2F%3EstrSubject%3A%3D%22Your%20Assigned%20Task%20is%20Due%20in%2010%20Days.%22%2C%20_%3CBR%20%2F%3EstrMessage%3A%3DstrEmployeeName%20%26amp%3B%20%22%3CBR%20%2F%3E%22%20%26amp%3B%20%22%3CBR%20%2F%3E%22%20%26amp%3B%20_%3CBR%20%2F%3EstrReminderText%20%26amp%3B%20%22%3CBR%20%2F%3E%22%20%26amp%3B%20%22%3CBR%20%2F%3E%22%2C%20_%3CBR%20%2F%3EstrEmailFROM%3A%3D%22YourSenderEmailAddress%40YourOrg.com%22%2C%20_%3CBR%20%2F%3EAttachment%3A%3DvbNullString)%3CBR%20%2F%3E.MoveNext%3CBR%20%2F%3ELoop%3CBR%20%2F%3EEnd%20With%3CBR%20%2F%3EexitProc%3A%3CBR%20%2F%3EvarX%20%3D%20SysCmd(acSysCmdRemoveMeter)%3CBR%20%2F%3EMe.Repaint%3C%2FP%3E%3CP%3EExit%20Sub%3C%2FP%3E%3CP%3EerrHandler%3A%3CBR%20%2F%3EMsgBox%20prompt%3A%3DErr%20%26amp%3B%20%22%3A%20%22%20%26amp%3B%20Err.description%2C%20buttons%3A%3DvbCritical%20%2B%20vbOKOnly%2C%20title%3A%3D%22Unexpected%20Error%22%3CBR%20%2F%3EResume%20exitProc%3CBR%20%2F%3EResume%3C%2FP%3E%3CP%3EEnd%20Sub%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPublic%20Function%20EmailReceiptByGeneric(%20_%3CBR%20%2F%3EByVal%20strReceipt%20As%20String%2C%20_%3CBR%20%2F%3EByVal%20Recipient%20As%20String%2C%20_%3CBR%20%2F%3EByVal%20ToAddress%20As%20String%2C%20_%3CBR%20%2F%3EByVal%20strProgram%20As%20String%2C%20_%3CBR%20%2F%3EByVal%20Attachment%20As%20String%2C%20_%3CBR%20%2F%3EByVal%20strSubject%20As%20String%2C%20_%3CBR%20%2F%3EByVal%20strMessage%20As%20String%2C%20_%3CBR%20%2F%3EByVal%20strEmailFROM%20As%20String%2C%20_%3CBR%20%2F%3EOptional%20ByVal%20CC%20As%20String)%20As%20Boolean%3C%2FP%3E%3CP%3EDim%20cdoConfig%20As%20Object%3CBR%20%2F%3EDim%20msgOne%20As%20Object%3CBR%20%2F%3E%3CBR%20%2F%3E'This%20example%20uses%20gmail.%20Modify%20to%20work%20with%20your%20email%20server.%3C%2FP%3E%3CP%3EOn%20Error%20GoTo%20errHandler%3CBR%20%2F%3EEmailReceiptByGeneric%20%3D%20False%3CBR%20%2F%3ESet%20cdoConfig%20%3D%20CreateObject(%22CDO.Configuration%22)%3CBR%20%2F%3EWith%20cdoConfig.Fields%3CBR%20%2F%3E.Item(%22%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsendusing%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsendusing%3C%2FA%3E%22)%20%3D%202%3CBR%20%2F%3E.Item(%22%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpserverport%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpserverport%3C%2FA%3E%22)%20%3D%20465%20'587%20'select%20the%20approproprate%20SMTP%20Port%20for%20your%20email%3CBR%20%2F%3E.Item(%22%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpserver%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpserver%3C%2FA%3E%22)%20%3D%20%22smtp.gmail.com%22%3CBR%20%2F%3E.Item(%22%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsendusername%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsendusername%3C%2FA%3E%22)%20%3D%20strEmailFROM%3CBR%20%2F%3E.Item(%22%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsendpassword%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsendpassword%3C%2FA%3E%22)%20%3D%20%22SupplyYourPasswordHere%22%3CBR%20%2F%3E.Item(%22%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpusessl%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpusessl%3C%2FA%3E%22)%20%3D%20True%3CBR%20%2F%3E.Item(%22%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpauthenticate%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpauthenticate%3C%2FA%3E%22)%20%3D%201%3CBR%20%2F%3E.Item(%22%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpconnectiontimeout%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fcdo%2Fconfiguration%2Fsmtpconnectiontimeout%3C%2FA%3E%22)%20%3D%2060%3CBR%20%2F%3E.Update%3CBR%20%2F%3EEnd%20With%3CBR%20%2F%3E%3CBR%20%2F%3ESet%20msgOne%20%3D%20CreateObject(%22CDO.Message%22)%3C%2FP%3E%3CP%3E%3CBR%20%2F%3ESet%20msgOne.Configuration%20%3D%20cdoConfig%3CBR%20%2F%3E%3CBR%20%2F%3EmsgOne.To%20%3D%20ToAddress%3CBR%20%2F%3EmsgOne.FROM%20%3D%20strEmailFROM%3CBR%20%2F%3EmsgOne.Subject%20%3D%20strSubject%3CBR%20%2F%3EmsgOne.htmlBody%20%3D%20strMessage%20%26amp%3B%20%22%3CBR%20%2F%3E%22%20%26amp%3B%20%22%3CBR%20%2F%3E%22%20%26amp%3B%20%22%3CBR%20%2F%3E%22%20%26amp%3B%20%22%3CBR%20%2F%3E%22%20%26amp%3B%20_%3CBR%20%2F%3EstrReceipt%3CBR%20%2F%3E%3CBR%20%2F%3EmsgOne.send%3CBR%20%2F%3EEmailReceiptByGeneric%20%3D%20True%3C%2FP%3E%3CP%3E%3CBR%20%2F%3ECleanup%3A%3C%2FP%3E%3CP%3EOn%20Error%20GoTo%200%3CBR%20%2F%3EOn%20Error%20Resume%20Next%3C%2FP%3E%3CP%3EexitProc%3A%3C%2FP%3E%3CP%3EExit%20Function%3CBR%20%2F%3E%3CBR%20%2F%3EerrHandler%3A%3CBR%20%2F%3EEmailReceiptByGeneric%20%3D%20False%3CBR%20%2F%3EMsgBox%20prompt%3A%3D%22There%20was%20an%20error%20in%20the%20attempt%20to%20send%20email%20through%20%22%20%26amp%3B%20strEmailFROM%20%26amp%3B%20%22.%22%20%26amp%3B%20vbCrLf%20%26amp%3B%20vbCrLf%2C%20_%3CBR%20%2F%3Ebuttons%3A%3DvbCritical%20%2B%20vbOKOnly%2C%20title%3A%3D%22Unable%20to%20Send%20Email%20through%20%22%20%26amp%3B%20strEmailFROM%3CBR%20%2F%3EResume%20Cleanup%3CBR%20%2F%3EResume%3C%2FP%3E%3CP%3EEnd%20Function%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor
I have a table with Tasks and due date. I would like to send automatic email remainders to the employees before 10 days for completion of due date. I am using ms access 2016 version how can i do it.
1 Reply

@Ramanareddy212798 

 

There are several components to this task including:

  • A way to select the tasks due in exactly 10 days
  • A way to select the email addresses for the employees assigned to those tasks
  • A way to compose and send the email notices.

The way to put that all together depends, in part, on how your tables are designed, and also on how you want to trigger this process. It also depends on what email client your organization uses. 

 

This is going to have to be a generic description since we don't have those details from you yet.

 

Write a query that selects tasks from the task table.


Select TaskID, TaskName, TaskDueDate,  EmployeeFirstName & " " & EmployeeLastName AS AssignedEmployee

FROM tblTask INNER JOIN tblEmployee On TblTask.AssignedEmployeeID = tblEmployee.EmployeeID

WHERE tblTask.TaskDueDate = DateAdd("D",10,Date) AND tblTask.TaskCompleteDate is Null;

 

Notice the WHERE clause. It assumes that you do not want to send reminders for tasks that have already been completed ahead of the due date and that you will do this every day, including weekends. If your organization doesn't want to include weekends, the process gets more complicated, of course.

You'll want to set up some method of triggering this process, which can be a command button on a form that a supervisor clicks, or an automatic process that runs when the accdb is opened every day or some other event occurs....

You will also need a VBA function to loop through the recordset generated by this query and send an email message to the employees selected.

Here's a template that you can modify to your situation.


Private Sub SendEmailReminder()

Dim varX As Variant
Dim rstEmailList As DAO.Recordset
Dim db As DAO.Database
Dim strSQL As String
Dim strReminder As String
Dim strEmployeeName As String
Dim strReminderText As String
Dim strToAddress as String
Dim lngTaskID As Long
Dim lngprogramID As Long

On Error GoTo errHandler

varX = SysCmd(acSysCmdInitMeter, "Please wait while the email list is prepared and sent...", 0)
Set db = CurrentDb
Set rstEmailList = db.OpenRecordset(Name:="qryTaskDueDate10DayReminder", options:=dbOpenDynaset)

With rstEmailList
Do While Not .EOF
strReminder = vbNullString
lngTaskID = ![TaskID]
strEmployeeName = !AssignedEmployee
strReminderText = "Your Assigned Task, " & !TaskName & ", is due in 10 days."
strToAddress = ![EmailAddress]
Call modEmail.EmailReminder( _
strReminder:=strReminder, _
Recipient:=strEmployeeName, _
ToAddress:=strToAddress, _
strSubject:="Your Assigned Task is Due in 10 Days.", _
strMessage:=strEmployeeName & "<br>" & "<br>" & _
strReminderText & "<br>" & "<br>", _
strEmailFROM:="YourSenderEmailAddress@YourOrg.com", _
Attachment:=vbNullString)
.MoveNext
Loop
End With
exitProc:
varX = SysCmd(acSysCmdRemoveMeter)
Me.Repaint

Exit Sub

errHandler:
MsgBox prompt:=Err & ": " & Err.description, buttons:=vbCritical + vbOKOnly, title:="Unexpected Error"
Resume exitProc
Resume

End Sub

 

 

Public Function EmailReceiptByGeneric( _
ByVal strReceipt As String, _
ByVal Recipient As String, _
ByVal ToAddress As String, _
ByVal strProgram As String, _
ByVal Attachment As String, _
ByVal strSubject As String, _
ByVal strMessage As String, _
ByVal strEmailFROM As String, _
Optional ByVal CC As String) As Boolean

Dim cdoConfig As Object
Dim msgOne As Object

'This example uses gmail. Modify to work with your email server.

On Error GoTo errHandler
EmailReceiptByGeneric = False
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465 '587 'select the approproprate SMTP Port for your email
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = strEmailFROM
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "SupplyYourPasswordHere"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Update
End With

Set msgOne = CreateObject("CDO.Message")


Set msgOne.Configuration = cdoConfig

msgOne.To = ToAddress
msgOne.FROM = strEmailFROM
msgOne.Subject = strSubject
msgOne.htmlBody = strMessage & "<br/>" & "<br/>" & "<br/>" & "<br/>" & _
strReceipt

msgOne.send
EmailReceiptByGeneric = True


Cleanup:

On Error GoTo 0
On Error Resume Next

exitProc:

Exit Function

errHandler:
EmailReceiptByGeneric = False
MsgBox prompt:="There was an error in the attempt to send email through " & strEmailFROM & "." & vbCrLf & vbCrLf, _
buttons:=vbCritical + vbOKOnly, title:="Unable to Send Email through " & strEmailFROM
Resume Cleanup
Resume

End Function