Comma-delimted text values to ListBox (1 Viewer)

LEXCERM

Registered User.
Local time
Today, 23:12
Joined
Apr 12, 2004
Messages
169
Hi all,

I have the following code on the "on-click" event of a listbox which populates a textbox:-
Code:
Dim strSelected As String
Dim varItem As Variant

With Me.lstClientCodes

    For Each varItem In .ItemsSelected
    strSelected = strSelected & "," & .ItemData(varItem)
    Next varItem
    
    Me.txtCodeString = Mid(strSelected, 2)
    
End With

Now, what I need is a kind of reverse. The listbox will already have pre-defined values, but I need specific ones highlighted based on the comma-delimited values from the textbox.

I have something like this at the moment, but not sure what I need to add:-
Code:
    myArray = Split(Forms![frm_NewCode]![txt_CodeString], ",")
    For i = LBound(myArray) To UBound(myArray)
        [COLOR="Red"][B]''' listbox to populate I presume[/B][/COLOR]
    Next

Many thanks in advance.
 

LEXCERM

Registered User.
Local time
Today, 23:12
Joined
Apr 12, 2004
Messages
169
[SOLVED] Comma-delimIted text values to ListBox

Found the solution:

Code:
    myArray = Split(Forms![frm_NewCode]![txt_CodeString], ",")

    For i = LBound(myArray) To UBound(myArray)
    
        For ii = 0 To Me.lstClientCodes.ListCount - 1
           If Me.lstClientCodes.Column(0, ii) = myArray(i) Then
              Me.lstClientCodes.Selected(ii) = True
           End If
        Next ii
        
    Next i

:)
 

Users who are viewing this thread

Top Bottom