Hi, iam using the below code to send Monthly salary slips to employees, and it working fine but having 2 issues
1. if the employee email in null, its stopping every thing ( need to edit to ignore if email not avaliable or at least if i closed the outlook email it will continues)
2. added a command at the end "DoCmd.OpenQuery "dbo_SalarySheet_Detail_Query_delete", i want it to work if any issues happened during the process
3. for each employee i have to confirm sending in outlook,, is there any way to make it automatic
1. if the employee email in null, its stopping every thing ( need to edit to ignore if email not avaliable or at least if i closed the outlook email it will continues)
2. added a command at the end "DoCmd.OpenQuery "dbo_SalarySheet_Detail_Query_delete", i want it to work if any issues happened during the process
3. for each employee i have to confirm sending in outlook,, is there any way to make it automatic
Code:
Private Sub Command0_Click()
DoCmd.OpenQuery "dbo_SalarySheet_Detail_Query_append"
Dim rsAccountNumber As DAO.Recordset
Dim strTo As Variant
Dim strSubject As String
Dim strMessageText As String
Set rsAccountNumber = CurrentDb.OpenRecordset("SELECT DISTINCT EmployeeID, [Email] FROM [dbo_SalarySheet_Detail_Query]", dbOpenSnapshot)
Debug.Print strTo
With rsAccountNumber
Do Until .EOF
DoCmd.OpenReport "Salary Slip", _
acViewPreview, _
WhereCondition:="EmployeeID = '" & !EmployeeID & "'", _
WindowMode:=acHidden
strTo = ![Email]
strSubject = "Salary Slip for the month of " & Month & ", " & Year & " "
strMessageText = "Dear Employee," & vbCrLf & "" & vbCrLf & "I trust this message finds you in good spirits. Attached herewith is your monthly salary Slip for the month of " & Month & ", " & Year & ". Kindly review the enclosed document to ensure the accuracy of all details. If you have any queries or require clarification regarding your salary or any related matter, please don't hesitate to contact the HR department." & vbCrLf & " " & vbCrLf & "We sincerely appreciate your ongoing commitment and efforts towards our organization. Your contributions are invaluable to our team. " & vbCrLf & "" & vbCrLf & "Warm regards," & vbCrLf & " " & vbCrLf & "HR Team"
DoCmd.SendObject ObjectType:=acSendReport, _
ObjectName:="Salary Slip", _
OutputFormat:=acFormatPDF, _
to:=strTo, _
Subject:=strSubject, _
MessageText:=strMessageText, _
EditMessage:=True
DoCmd.close acReport, "Salary Slip", acSaveNo
.MoveNext
Loop
.close
End With
DoCmd.OpenQuery "dbo_SalarySheet_Detail_Query_delete"
End Sub