Here is my code
Private Sub cmdEmailAll_Click()
'output all reports at once
Dim i As Long
Dim olApp As Object
Dim olMail As Object
Const olMailItem = 0
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If Err.Number = 429 Then
Err.Clear
'Outlook is not running; open Outlook with CreateObject
Set olApp = CreateObject("Outlook.Application")
End If
'for looping listbox entries
For i = 0 To Me.List0.ListCount - 1
'choose the ones with email only
If (Me.listWithEmails.Column(1, i)) = "" Then
Else
Me.listWithEmails.Selected(i) = True
Me.List0.Column(0, i)
clientSelected = Me.listWithEmails.Column(0, i)
fileToMailLocation = "C:\Desktop\" & clientSelected & ".pdf"
fileToMailLocation, False
DoCmd.OutputTo acOutputReport, "Monthly Statement", acFormatPDF, fileToMailLocation, False
Set olMail = olApp.CreateItem(olMailItem)
With olMail
.To = Me.listWithEmails.Column(1, i)
.subject = statementMonth & " Statement"
.Attachments.Add fileToMailLocation
.Display
End With
End If
Next i
Set olMail = Nothing
Set olApp = Nothing
End Sub
======================
If my list has less than 18 names then I have extra email(s) open without email address. If the list has more than 18 names then I have only the first 18 emails open.