Presumably you have 3 tables:
- tblClient: one record for each person, with ClientID primary key.
- tblRole: one record for each role, with RoleID primary key.
- tblClientRole: one record for each valid combination, with fields:
ClientID (foreign key to tblClient.ClientID), and
RoleID (foreign key to tblRole.RoleID).
Now you want to set the RowSource of your list box, based on the state of
the various toggle buttons.
In the end, the RowSource will be a string that looks like this:
SELECT DISTINCT tblClient.ClientID, tblClient.Surname, tblClient.FirstName
FROM tblClient INNER JOIN tblClientRole ON tblClient.ClientID =
tblClientRole.ClientID
WHERE tblClientRole.RoleID IN (2, 8, 12, 99)
ORDER BY tblClient.Surname, tblClient.FirstName;
The IN (...) will be determined by which toggle buttons are depressed. The
example below assumes you have toggle buttons named tgl1, tgl2, tgl3, etc.
When the button is depressed, its value is True. The code responds to the
updated state of the button by building the SQL string based on the
depressed buttons. If no buttons are depressed, no people are returned. The
name of the list box is assumed to be List1.
Private Sub tgl1_AfterUpate
Dim strSql As String
Dim lngLen As Long
Const strcStub = "SELECT DISTINCT tblClient.ClientID, tblClient.Surname,
tblClient.FirstName FROM tblClient INNER JOIN tblClientRole ON
tblClient.ClientID = tblClientRole.ClientID WHERE "
Const strcTail = " ORDER BY tblClient.Surname, tblClient.FirstName;"
Const strcSep = ", "
If Me.tgl1.Value Then
strSql = strSql & "1" & strcSep
End If
If Me.tgl2.Value Then
strSql = strSql & "2" & strcSep
End If
'etc for other toggle buttons.
lngLen = Len(strSql) - Len(strcSep) 'Without trailing comma and
space.
If lngLen > 0 Then
strSql = strcStub & "(tblClientRoleID IN (" & Left$(strSql, lngLen)
& "))" & strcTail
Else
strSql = strcStub & "(False)" & strcTail
End If
'Debug.Print strSql
Me.List1.RowSource = strSql
End Sub
Private Sub tgl2_AfterUpdate
Call tgl1_AfterUpate
End Sub
Private Sub tgl3_AfterUpdate
Call tgl1_AfterUpate
End Sub
The other toggle buttons will also Call tgl1_AfterUpate.
That's aircode, but hopefully you can apply to your situation.
[quoted text clipped - 6 lines]
to do this using toggle buttons so when you click on and off the button id
adds and removes the people with those roles from the list