Pre-Selecting Items in a List Box

mikebrewer

Registered User.
Local time
Today, 13:10
Joined
Sep 28, 2011
Messages
93
Hey guys,

I have a form that loads with a list box of names. The names have an associated ID number that is not shown in the list box but when the user chooses one of the names, I'm saving the list of their selections (ID #s) to their user profile so that I can reload the form with the same items selected. So the example is that I am the user, I open the form and select 3 names from the list and the names correspond to ID #s 1, 4, 15. I save "1,4,15" into a field associated with the current user. Now what I want to do is highlight the names associated with 1,4,15 the next time that the user opens that form. I can get the string into an array and flow through it... I just don't know how to select the items in the list box correctly. Any help would be appreciated.

Thanks!
 
Code:
Dim i As Integer

For i = 0 To Me.lstMyList.ListCount - 1
    If Nz(DLookup("ID", "UserPreference", "User = '" & varUserName & "' AND ForeignID = " & Me.lstMyList.ItemData(i)), 0) > 0 Then
        Me.lstMyList.Selected(i) = True
    Else
        Me.lstMyList.Selected(i) = False
    End If
Next i
 

Users who are viewing this thread

Back
Top Bottom