I am working on a CDO email database that has a multi-select listbox. When I make a selection in the listbox and click on the send e-mail button, it will send an e-mail based on the record(s) selected in the listbox. The issue that I am having is, I can make a selection int the listbox but it only sends information based on the first record in the listbox. I can't seem to get it to loop. Below is part of the code that I am having issues with. Any help is appreciated.
Dim mailaddress As Variant
For Each mailaddress In Me!lstorders.ItemsSelected
With objmsg
Set .Configuration = objconf
lngCustomerID = Me!lstorders.Column(0, i) '<< grab the customer id
.From = Me!txtEmailFrom.Value
strTo = Me!lstorders.Column(1, i) ' << the email address to column
.To = strTo '<<< grabs the 1st column value in the list (zero based loop)
If Me!txtCCTo <> "" Then .CC = Me!txtCCTo
If Me!txtBCCTo <> "" Then .BCC = Me!txtBCCTo
.Subject = Me!txtSubjectHeading.Value
.TextBody = Me!lstorders.Column(9, i) '<<< grabs the 9th column the text body
If FetchDeliveryReport() = False Then
.DSNOptions = cdoDSNNever
Else
.DSNOptions = cdoDSNSuccessFailOrDelay
End If
.Fields.Update
PleaseWait ("Sending email via SMTP server to..." & strTo)
.Send
PleaseWait ("Still communicating with server and and dealing with C.D.O. connections be patient...")
End With
i = i + 1
If Err.Number = 0 Then ' << append to log only if we have not errored in the loop
If bool_log Then ' << but only if the config table activate log field says true
x = AppendToActivityLog(lngCustomerID, Me!txtEmailFrom.Value, strTo, Me!txtCCTo, Me!txtBCCTo)
End If
End If
DoEvents
Next
PleaseWait ("")
Set objmsg = Nothing
Set objconf = Nothing
Set objFlds = Nothing
SendMailByC_D_O = Err.Number
Dim mailaddress As Variant
For Each mailaddress In Me!lstorders.ItemsSelected
With objmsg
Set .Configuration = objconf
lngCustomerID = Me!lstorders.Column(0, i) '<< grab the customer id
.From = Me!txtEmailFrom.Value
strTo = Me!lstorders.Column(1, i) ' << the email address to column
.To = strTo '<<< grabs the 1st column value in the list (zero based loop)
If Me!txtCCTo <> "" Then .CC = Me!txtCCTo
If Me!txtBCCTo <> "" Then .BCC = Me!txtBCCTo
.Subject = Me!txtSubjectHeading.Value
.TextBody = Me!lstorders.Column(9, i) '<<< grabs the 9th column the text body
If FetchDeliveryReport() = False Then
.DSNOptions = cdoDSNNever
Else
.DSNOptions = cdoDSNSuccessFailOrDelay
End If
.Fields.Update
PleaseWait ("Sending email via SMTP server to..." & strTo)
.Send
PleaseWait ("Still communicating with server and and dealing with C.D.O. connections be patient...")
End With
i = i + 1
If Err.Number = 0 Then ' << append to log only if we have not errored in the loop
If bool_log Then ' << but only if the config table activate log field says true
x = AppendToActivityLog(lngCustomerID, Me!txtEmailFrom.Value, strTo, Me!txtCCTo, Me!txtBCCTo)
End If
End If
DoEvents
Next
PleaseWait ("")
Set objmsg = Nothing
Set objconf = Nothing
Set objFlds = Nothing
SendMailByC_D_O = Err.Number