I am trying to go through a recordset and create changing reports to send out via email. The email function works but keeps sending out the same report to the entire list of emails. Still a big time Access n00b so any help would be appreciated. The report is supposed to pull from 'Customer Table' and has a subreport in it to pull from 'Customer Product Table' which both have a Customer Code in common
Code:
Dim rs As New ADODB.Recordset
Dim sSQL As String
Dim x As Long
Dim i, sec As Long
Dim varItm As Variant
Dim varCustEmail As Variant
Dim varConditionString As Variant
Const FAX_Number = 2
Const Stored_Fax_Number = 3On Error GoTo ROUTINE_ERROR
Select Case fraContactOptions.Value
Case 1
'SENDS TO REGULAR REPORT
sSQL = "SELECT [Customer Table].[Company Email], [Customer Table].[Customer Code], [Customer Table].[Stored Fax Number], [Customer Table].[Company Name] FROM [Customer Table] WHERE [Customer Table].[Fax Terminal Report]=0 AND [Customer Table].[Send Customer Email]=True ORDER BY [Customer Table].[FAX Number];"
rs.Open sSQL, CurrentProject.Connection, adOpenStatic, adLockOptimistic
MsgBox "WARNING! Open Email Program Before Hitting OK"
i = 1
While Not rs.EOF
varConditionString = "[Customer Table].[Customer Code] = " & rs.Fields("Customer Code").Value & " "
varCustEmail = rs.Fields("Company Email").Value
DoCmd.OpenReport "Daily EMAIL Price List Report", acViewPreview, , varConditionString
DoEvents
Wait (2)
DoCmd.SendObject acReport, "Daily EMAIL Price List Report", acFormatRTF, varCustEmail, , , rs.Fields("Company Name").Value & " - Daily Pricing Report", "Please find attached your daily pricing report.", False
DoCmd.Close acReport, "Daily EMAIL Price List Report", acSaveNo
Wait (2)
DoEvents
i = i + 1
rs.MoveNext
Wend
rs.Close
Set rs = Nothing