Question Listbox Looping Issues (1 Viewer)

rywello

Registered User.
Local time
Today, 16:29
Joined
Jan 13, 2016
Messages
68
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
 

rywello

Registered User.
Local time
Today, 16:29
Joined
Jan 13, 2016
Messages
68
Do I put that in place of the For Each code that I have?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:29
Joined
Aug 30, 2003
Messages
36,127
Not necessarily, I mean try using that variable:

lngCustomerID = Me!lstorders.Column(0, mailaddress)
 

rywello

Registered User.
Local time
Today, 16:29
Joined
Jan 13, 2016
Messages
68
It is still not working fully. I have attached a copy of my database if you could take a look. You need to click the configuration screen to put your SMTP address if you need to. Thanks for your help.
 

Attachments

  • Listbox.zip
    358.3 KB · Views: 368

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:29
Joined
Aug 30, 2003
Messages
36,127
What exactly does "not working fully" mean? You're still using the "i" variable for the body.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:29
Joined
Aug 30, 2003
Messages
36,127
Happy to help, and welcome to the site by the way!
 

Users who are viewing this thread

Top Bottom