1. I submit score cards to suppliers on a monthly basis.
2. I have a table with supplier names and email address. If the supplier is currently active the “Inactive” check box field in that record in not checked. Additional suppliers could be added at any time. Existing suppliers could become inactive then reactivated at a later date. Only active suppliers (those without the “Inactive” check-box field checked) should ever be listed.
3. I have a form with a combo box to filter and display the score card data in a subform for that selected supplier.
4. I use a VBA process that emails the filtered data to the supplier selected in the combo box. As there are numerous suppliers, I am looking to automate this process so I do not have to manually select suppliers individually and email them their individually filtered report.
I found some code online that enables me, with one-click, to send an email to individual suppliers using the email address as listed in my supplier table. The code allows me to add a subject line and message body for each supplier by name.
Here is what I now need:
1. I want to use VBA to filter the data for the report for each supplier within the supplier table.
2. Attach the filtered report to the email being sent to that supplier. Filter and email only the data for the selected supplier and not all data to all suppliers.
3. Loop this process for each active supplier in the supplier table; inactive check-box field is not checked in the supplier table.
I hope I explained this well enough to get some haelp.
Any assistance would be GREATLY appreciated!!
Here is the code I am currently working with:
Expand|Select|Wrap|Line Numbers
- Private Sub cmdOneClickMassEmail_Click()
- On Error GoTo ErrorMessage
- Set OutApp = CreateObject("Outlook.Application")
- Dim rs As DAO.Recordset
- Set rs = CurrentDb.OpenRecordset("_tmpSuppliers")
- Dim rp = CurrentReportingPeriod
- With rs
- If .EOF And .BOF Then
- MsgBox "No emails will be sent becuase there are no records assigned from the list", vbInformation
- Else
- Do Until .EOF
- stremail = ![SupplierToEmailAdderss]
- stremailcc = ![SupplierCCEmailAdderss]
- strsubject = "Score Card for " & ![SupplierName] & " - " & DLookup("[Current Period]", "[qrySelect_CurrentReportingPeriodMonthAndYear]", "[Current Period]")
- strbody = "Dear " & ![SupplierName] & "," & vbCrLf & _
- "Email message body goes here."
- Set OutMail = OutApp.CreateItem(olMailItem)
- With OutMail
- .To = stremail
- .CC = stremailcc
- .BCC = ""
- .Subject = strsubject
- .Body = strbody
- .Send
- End With
- .MoveNext
- Loop
- End If
- End With
- Exit_cmdOneClickMassEmail_Click:
- Exit Sub
- ErrorMessage:
- MsgBox Err.Description
- Resume Exit_cmdOneClickMassEmail_Click
- End Sub