I have to send email messages to Company TAC Officers/TACNCOs every so often about upcoming briefings.
I have a list of cadets (in table cadets) with their personnel information plus the company/regiment that they are assigned to (e.g., A1, C2, etc). Comp_reg can go from A to H and 1 to 4 (32 different possibilities).
The following code will email the TAC, and TACNCO a list of assigned cadets (if any) and their presentation date, time, and project name. The report that is emailed is based on a query that has a criteria for A1.
How can I automate this where I don't have to make 32 different reports? Because I have to do this 4 times a semester, I don't want to change fields in the report from IPR_date#2 to IPR_date#3, etc.
Private Sub Command162_Click()
On Error GoTo Err_Command162_Click
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb
Dim SQLString As String
SQLString = "SELECT DISTINCT [TAC_Email] & '@usma.edu' AS T_Email, [TACNCO_Email] & '@usma.edu' AS TN_Email FROM
Cadets INNER JOIN TAC_Email ON Cadets.TAC_Lastname =
TAC_Email.TAC_Lastname WHERE (((Cadets.Comp_Reg)='A1'))"
Set rst = db.OpenRecordset(SQLString)
rst.MoveFirst
DoCmd.SendObject acSendReport, "ReportA1",
acFormatHTML, rst!T_Email, rst!TN_Email, , "Invitation to
SE402 IPR", "This is an excellent opportunity...", True
rst.Close
db.Close
Exit_Command162_Click:
Exit Sub
Err_Command162_Click:
MsgBox Err.Description
Resume Exit_Command162_Click
End Sub
Thank you in advance
Greg
I have a list of cadets (in table cadets) with their personnel information plus the company/regiment that they are assigned to (e.g., A1, C2, etc). Comp_reg can go from A to H and 1 to 4 (32 different possibilities).
The following code will email the TAC, and TACNCO a list of assigned cadets (if any) and their presentation date, time, and project name. The report that is emailed is based on a query that has a criteria for A1.
How can I automate this where I don't have to make 32 different reports? Because I have to do this 4 times a semester, I don't want to change fields in the report from IPR_date#2 to IPR_date#3, etc.
Private Sub Command162_Click()
On Error GoTo Err_Command162_Click
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb
Dim SQLString As String
SQLString = "SELECT DISTINCT [TAC_Email] & '@usma.edu' AS T_Email, [TACNCO_Email] & '@usma.edu' AS TN_Email FROM
Cadets INNER JOIN TAC_Email ON Cadets.TAC_Lastname =
TAC_Email.TAC_Lastname WHERE (((Cadets.Comp_Reg)='A1'))"
Set rst = db.OpenRecordset(SQLString)
rst.MoveFirst
DoCmd.SendObject acSendReport, "ReportA1",
acFormatHTML, rst!T_Email, rst!TN_Email, , "Invitation to
SE402 IPR", "This is an excellent opportunity...", True
rst.Close
db.Close
Exit_Command162_Click:
Exit Sub
Err_Command162_Click:
MsgBox Err.Description
Resume Exit_Command162_Click
End Sub
Thank you in advance
Greg