I have a callback function to fill a list box that goes like this:
This is basically a list of database users, and whether or not they are currently logged on to the database. What I want to do is, if the user is logged on, turn that list item green, and if they are not logged on, turn it red. So here's what I tried to do:
...
...
This not only doesn't work, it messes up the rest of the data in the list box. What am I doing wrong? Is this kind of thing even possible?
--Ryan
Code:
Function FillList(ctl As Control, varID As Variant, lngRow As Long, lngCol As Long, intCode As Integer) As Variant
On Error GoTo Err_FillList
Dim varRetval As Variant
Static db As DAO.Database
Static rstData As DAO.Recordset
Select Case intCode
Case acLBInitialize
Set db = CurrentDb()
Set rstData = db.OpenRecordset("SELECT [tbl Users].Name, [tbl Users].Online FROM [tbl Users];")
varRetval = True
Case acLBOpen
varRetval = Timer
Case acLBGetRowCount
rstData.MoveLast
varRetval = rstData.RecordCount + 1
Case acLBGetColumnCount
varRetval = 2
Case acLBGetColumnWidth
varRetval = -1
Case acLBGetValue
Select Case lngRow
Case 0
Select Case lngCol
Case 0
varRetval = "Name"
Case 1
varRetval = "Online?"
End Select
Case Else
rstData.MoveFirst
rstData.Move lngRow - 1
Select Case lngCol
Case 0
varRetval = rstData(lngCol)
Case 1
varRetval = Switch(rstData(lngCol) = -1, "Yes", rstData(lngCol) = 0, "No")
End Select
End Select
Case acLBGetFormat
varRetval = -1
Case acLBEnd
Set rstData = Nothing
Set db = Nothing
End Select
FillList = varRetval
Exit_FillList:
Exit Function
Err_FillList:
MsgBox err.Number & ": " & err.Description
Resume Exit_FillList
End Function
...
Code:
Case acLBGetFormat
If rstData(1) = -1 then
retval = "[green]"
Else
varRetval = "[red]"
End If
This not only doesn't work, it messes up the rest of the data in the list box. What am I doing wrong? Is this kind of thing even possible?
--Ryan