Hello. I have the following code to add the items selected in a multi-select listbox to the table. If item 2 or 6 is selected, part of the text needs to be replaced. The part in the middle where I have the If statements is giving me trouble. If I only select one of those items, it works to add it to the table and replace the placeholder text with what the user typed into the textbox. But if I select both item 2 and item 6, it is only replacing text on item 2, and inserts item 6 with the placeholder text still. How can I change this so anytime 2 or 6 is selected, it replaces the text on both? Thank you for any help you can provide!
Code:
'add selected value(s) to table
Set ctl = Me.lstCust
For Each varItem In ctl.ItemsSelected
rs.AddNew
rs!DocumentNeeded = ctl.ItemData(varItem)
If Me.lstCust.Selected(2) = True Then
Debug.Print ctl.Column(2, varItem), Me.LicensingAgent
rs!DocNeededDesc = Replace(ctl.Column(2, varItem), "(agency name)", Me.LicensingAgent)
ElseIf Me.lstCust.Selected(6) = True Then
Debug.Print ctl.Column(2, varItem), Me.txtOR
rs!DocNeededDesc = Replace(ctl.Column(2, varItem), "(documents)", Me.txtOR)
Else: rs!DocNeededDesc = ctl.Column(2, varItem)
End If
rs!State2StateID = Me.ID
rs.Update