I have found numerous examples, both in books and online, of using callback functions to populate a listbox, but all the examples I have come across (that I understand) are for ONE column listboxes...I am VERY stumped (expecially by the acLBInitialize part) how to make this function work for a 2 column listbox...
What I am trying to do is make a listbox that shows each user in cat.Users and then in the next column, the corresponding Group that the user belongs to (each user only belongs to one group).
My code is as follows and I appreciate any insight anyone may have!!! Thanx!!!
Function FillUsersGroupsList(ctl As Control, id As Variant, col As Variant, _
row As Variant, Code As Variant) As Variant
Static intRows As Integer
Dim varRetVal As Variant
Dim cat As ADOX.Catalog
Dim usr As ADOX.User
Dim grp As ADOX.Group
Set ctl = Me.List34
Static sastrUsers() As String
Static sastrGroups() As String
Select Case Code
Case acLBInitialize
Set cat = New ADOX.Catalog
cat.ActiveConnection = CurrentProject.Connection
For Each usr In cat.Users
sastrUsers(intRows) = usr.Name 'this gives me a subscript error
intRows = intRows + 1
Next usr
'do I need a similar section for sastrGroups?
'how to indicate to create a list of each user (column 1) then user's group (column2) in each row?
varRetVal = intRows
Case acLBOpen
varRetVal = Timer
Case acLBGetRowCount
varRetVal = intRows
Case acLBGetColumnCount
varRetVal = 2
Case acLBGetColumnWidth
Select Case col
Case 0:
varRetVal = -1
Case 1:
varRetVal = -1
End Select
Case acLBGetValue
Select Case row
Case 0
Select Case col
Case 0
varRetVal = "User"
Case 1
varRetVal = "Access Group"
End Select
Case Else
Select Case col
Case 0
varRetVal = sastrUsers(row)
Case 1
varRetVal = sastrGroups(col)
End Select
End Select
End Select
FillUsersGroupsList = varRetVal
End Function
What I am trying to do is make a listbox that shows each user in cat.Users and then in the next column, the corresponding Group that the user belongs to (each user only belongs to one group).
My code is as follows and I appreciate any insight anyone may have!!! Thanx!!!
Function FillUsersGroupsList(ctl As Control, id As Variant, col As Variant, _
row As Variant, Code As Variant) As Variant
Static intRows As Integer
Dim varRetVal As Variant
Dim cat As ADOX.Catalog
Dim usr As ADOX.User
Dim grp As ADOX.Group
Set ctl = Me.List34
Static sastrUsers() As String
Static sastrGroups() As String
Select Case Code
Case acLBInitialize
Set cat = New ADOX.Catalog
cat.ActiveConnection = CurrentProject.Connection
For Each usr In cat.Users
sastrUsers(intRows) = usr.Name 'this gives me a subscript error
intRows = intRows + 1
Next usr
'do I need a similar section for sastrGroups?
'how to indicate to create a list of each user (column 1) then user's group (column2) in each row?
varRetVal = intRows
Case acLBOpen
varRetVal = Timer
Case acLBGetRowCount
varRetVal = intRows
Case acLBGetColumnCount
varRetVal = 2
Case acLBGetColumnWidth
Select Case col
Case 0:
varRetVal = -1
Case 1:
varRetVal = -1
End Select
Case acLBGetValue
Select Case row
Case 0
Select Case col
Case 0
varRetVal = "User"
Case 1
varRetVal = "Access Group"
End Select
Case Else
Select Case col
Case 0
varRetVal = sastrUsers(row)
Case 1
varRetVal = sastrGroups(col)
End Select
End Select
End Select
FillUsersGroupsList = varRetVal
End Function