combo box selective highlighting problem

  • Thread starter Thread starter ruchie
  • Start date Start date
R

ruchie

I have a table of users assigned various projects. normally a user is
assigned multiple projects, and for that, multiple entries of the user
is created within the table, with ofcourse the unique names of
projects. eg:
Name Project
acb project 1
acb project 2
acb project 3
xyz project 2
xyz project 3

i have a combo box in a form in which i am displaying just a list of
all the projects. when i select a particular user's name from a drop-
down in the form, i need to highlight all the projects the user is
assigned to in combo box list. ofcourse, multiple selections in the
combo box are allowed in this case.
is there a way to do that?
 
You'll have to use code to loop through the projects assigned to the user,
and set the Selected property of the rows in the list box.

Something like:

Dim rsProjects As DAO.Recordset
Dim lngLoop As Long

Set rsProjects = CurrentDb.OpenRecordset( _
"SELECT Projects FROM Table " & _
"WHERE UserId = '" & Me.UserId & "'")
Do While Not rsProjects.EOF
For lngLoop = 0 To Me.Listbox.ListCount - 1
If Me.Listbox.ItemData(lngLoop) = RsProjects!Projects
Me.Listbox.Select(lngLoop) = True
Exit For
End If
Next lngLoop
rsProject.MoveNext
Loop
rsProject.Close
Set rsProject = Nothing
 
Back
Top