MultiSelect Listbox to Table

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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!)
 
Back
Top