I'm a novice with VBA in Access and I have ran into a problem. If someone has some ideas I would appreciate it.
I have a list of managers in the "tblReports To" table (reportsTo is the field). I need to loop through this table, grabbing data from the "tbl5ManagerApp roval" table, using the query "qry5MgrApp v" and generate a report(rpt5MgrA pporval)which is then emailed to that manger.
What I have for code is below:
I have a list of managers in the "tblReports To" table (reportsTo is the field). I need to loop through this table, grabbing data from the "tbl5ManagerApp roval" table, using the query "qry5MgrApp v" and generate a report(rpt5MgrA pporval)which is then emailed to that manger.
What I have for code is below:
Code:
Private Sub Command58_Click()
On Error GoTo Exit_Command58_Click
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("tblReportsTo") 'table
Dim stDocName As String
Dim strSQL As String
stDocName = "rpt5MgrApproval"
DoCmd.SetWarnings False
rs.MoveFirst
Do While Not rs.EOF
strSQL = "SELECT * FROM tblMgrApproval WHERE reportsto= """ & rs!reportsto & """"
DoCmd.SendObject acReport, stDocName, "PdfFormat(*.pdf)", rs!emailAddress, "", "", "Manager Approval", "", True, """"""
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
MsgBox "Reports Completed", vbOKOnly, "Month End PTO"
Exit_Command58_Click:
If MsgBox("Do you want to cancel the run?", vbQuestion Or vbYesNo) = vbYes Then
Exit Sub
Else
Resume Next
End If
End Sub
Comment