You might like to take a look at InvoicePDF.zip in my public databases folder at:
https://onedrive.live.com/?cid=44CC60D7FEA42912&id=44CC60D7FEA42912!169
This little demo file includes an option to email multiple invoices to multiple customers as PDF attachments. In the demo the invoices are selected in a multi-select list box, and emailed by the code below. Each instance of the report is restricted to the invoices for a single customer by virtue of the report's RecordSource query referencing as a parameter a hidden text box in the form containing a value list of invoice numbers, using the GetToken and InParam functions published by Microsoft some years ago.
Private Sub cmdEmail_Click()
Const MESSAGE_TEXT_1 = "No invoices selected."
Dim rst As DAO.Recordset
Dim strSQL As String
Dim strAddressee As String
Dim strTo As String
Dim strSubject As String
Dim strMessageText As String
Dim strCustomerList As String
Dim lngTo As Long
Dim lngCustomerID As Long
Dim varItem As Variant
With Me.lstInvoices
If .ItemsSelected.Count = 0 Then
MsgBox MESSAGE_TEXT_1, vbExclamation, "Invalid Operation"
Exit Sub
End If
lngCustomerID = 0
'loop through selected items in list box and build
'a distinct value list of selected CustomerID values
For Each varItem In .ItemsSelected
If Val(.Column(2, varItem)) > lngCustomerID Then
lngCustomerID = Val(.Column(2, varItem))
strCustomerList = strCustomerList & "," & lngCustomerID
End If
Next varItem
End With
' remove leading comma
strCustomerList = Mid(strCustomerList, 2)
' establish a recordset of distinct selected CustomerID values
strSQL = "SELECT CustomerID FROM Customers WHERE CustomerID IN(" & strCustomerList & ")"
Set rst = CurrentDb.OpenRecordset(strSQL)
rst.MoveLast
rst.MoveFirst
' loop through recordset and build and open an email to each customer
Do While Not rst.EOF
Me.txtInvoiceList = ""
With Me.lstInvoices
If .ItemsSelected.Count > 0 Then
For Each varItem In .ItemsSelected
' if selected customer = current customer from recordset
' assign values to variables for use in email
' and increment list of invoice numbers for selected customer
If Val(.Column(2, varItem)) = rst.Fields("CustomerID") Then
strAddressee = .Column(1, varItem)
strTo = .Column(4, varItem)
lngTo = .Column(2, varItem)
Me.txtInvoiceList = Me.txtInvoiceList & "," & .ItemData(varItem)
End If
Next varItem
'remove leading comma
Me.txtInvoiceList = Mid(Me.txtInvoiceList, 2)
strSubject = "Invoice Numbers " & Replace(txtInvoiceList, ",", "; ")
strMessageText = strAddressee & ":" & _
vbNewLine & vbNewLine & _
"The above invoices are attached." & _
vbNewLine & vbNewLine & _
"Customer Accounts Department, Widget Supply Company"
' output report as PDF file attached to email to selected customer
DoCmd.SendObject ObjectType:=acSendReport, _
ObjectName:="rptInvoiceMultiple_Email", _
OutputFormat:=acFormatPDF, _
To:=strTo, _
Subject:=strSubject, _
MESSAGETEXT:=strMessageText, _
EditMessage:=True
Else
MsgBox MESSAGE_TEXT_1, vbExclamation, "Invalid Operation"
End If
End With
rst.MoveNext
Loop
End Sub
Note that the code uses the SendObject method of the DoCmd object to generate the emails rather than opening an instance of Outlook by means of automation.