emjohnson7
New Member
- Joined
- Apr 6, 2019
- Messages
- 5
Hi there,
I am working on some reports – I need to replace the “name”with a query that goes through 67 names in a loop.
DoCmd.OpenReport "Report - Change Month in Title eachtime", acViewPreview, "", "
![Send ReportTo]=""name""", acNormal
Below is my entire code thus far. I can get the email portion to work with thequery, but I cannot with the opening the report. Please help.
Thank you!!
I am working on some reports – I need to replace the “name”with a query that goes through 67 names in a loop.
DoCmd.OpenReport "Report - Change Month in Title eachtime", acViewPreview, "", "
Code:
[FONT=Calibri][SIZE=3][COLOR=#000000]Function SendEmails()[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] Dim strSQL AsString[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] Dim SendToEmail AsString[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] DimReportRecipient As String[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] Set db = CurrentDb[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] ' Use the nextlines to define and open the query that identifies all unique "SendTo" values. Replace the SQL I havebelow with the proper SQL[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] strSQL ="SELECT DISTINCT Ownership - VP Level].[Send Report To], UserInfo.[Workemail] FROM UserInfo INNER JOIN [Ownership - VP Level] ON UserInfo.Name = [Ownership- VP Level].[Last, First];"[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] Set rst =db.OpenRecordset(strSQL)[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] ' Scroll thru therecordset[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] With rst[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] Do Until .EOF[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] ReportRecipient = ![Send Report To][/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] SendToEmail = ![Work email][/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] ' Storethe value in the Send To field of the current record[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] DoCmd.OpenReport "Report - Change Month in Title each time",acViewPreview, "", "[Table]![Send Report To]=""name""",acNormal[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] DoCmd.SendObject acReport, "Report - Change Month in Title eachtime", "PDFFormat(*.pdf)", SendToEmail, "","", "REPORT TEST EMAIL", "This is a test to see if theemails will be sent properly.", True, ""[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] DoCmd.Close acReport, "Report - Change Month in Title eachtime"[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] .MoveNext[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] Loop[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] .Close[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] End With[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] Set rst = Nothing[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] Set db = Nothing[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[FONT=Calibri][SIZE=3][COLOR=#000000]End Function[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
Last edited by a moderator: