MultiSelect Listbox to Table

M

MSU Sptn2

I would like to list the items selected in a multi-select list box in a table
field. I have a list box displaying email addresses and I would like to
enter the selected addresses to a table field separated by a semicolon so
when my SendObject command references the table field, it will send the email
to all addresses in the field. I have the following code, but it just
inserts NA to everything. I am new at this and I can't find the problem.
Any suggestions?

Dim i As Integer
Dim var As Variant
Dim strEmails As String

If lstProgram_Manager.Selected(i) = True Then
For Each var In Me.lstProgram_Manager.ItemsSelected
strEmails = strEmails & Me.lstProgram_Manager.Column(1, var) & ";"
Next var

CurrentDb.Execute "UPDATE TblCompliance SET T_Reminder_Mailing_List='" &
strEmails & "' WHERE AN_AutoNumber = " & Me!txtAN_AutoNumber

ElseIf lstProgram_Manager.Selected(i) = False Then

CurrentDb.Execute "UPDATE TblCompliance SET T_Reminder_Mailing_List='" &
"NA" & "' WHERE AN_AutoNumber = " & Me!txtAN_AutoNumber

End If
 
D

Douglas J. Steele

All the following does

If lstProgram_Manager.Selected(i) = True Then

is tell whether the first row in the listbox is selected or not.

Assuming you want to know whether anything's selected in the list box, you
need

If lstProgram_Manager.ItemsSelected.Count > 0 Then


(BTW, there's no reason for the ElseIf. Else is sufficient, since you've got
a binary situation!)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Null is not null! 3
Multi Select Listbox to Table field 1
Listbox to Table Field 3
Error: Invalid Argument 3
Search pattern 3
email distribution Error 87 0
Please help to email reports in snp files 0
Bulk Email 2

Top