What happens (or doesn't happen)?Still not working
Probably not.should I change the list box to multiple select?
I have attached the db with some sample data.What happens (or doesn't happen)?
Remember we can't see your screen! Please describe the steps you take and what you observe.
Probably not.
I posted the db in another reply aboveCan you post a copy of the database (zip format) with enough records to highlight the issue?
Dim SelectedID As Integer
Dim index As Integer
If Not CurrentProject.AllForms("Contact List").IsLoaded Then Exit Sub
With lbSearchResults
If .ItemsSelected.Count > 0 Then
For index = 0 To .ListCount - 1
If .Selected(index) Then
SelectedID = .Column(0, index)
End If
Next
Forms![Contact List].Filter = "ID = " & SelectedID
Forms![Contact List].FilterOn = True
Else
Forms![Contact List].FilterOn = False
End If
End With
Still not filtering.test this.
Code:Dim SelectedID As Integer Dim index As Integer If Not CurrentProject.AllForms("Contact List").IsLoaded Then Exit Sub With lbSearchResults If .ItemsSelected.Count > 0 Then For index = 0 To .ListCount - 1 If .Selected(index) Then SelectedID = .Column(0, index) End If Next Forms![Contact List].Filter = "ID = " & SelectedID Forms![Contact List].FilterOn = True Else Forms![Contact List].FilterOn = False End If End With
I made the list to allow multiple selection, and when selecting more than one record, it is returning only one. (The last one to be specific)Still not filtering.
Am guessing because no selection is being made.
Dim SelectedID As String
Dim index As Integer
If Not CurrentProject.AllForms("Contact List").IsLoaded Then Exit Sub
With lbSearchResults
If .ItemsSelected.Count > 0 Then
For index = 0 To .ListCount - 1
If .Selected(index) Then
SelectedID = SelectedID & .Column(0, index) & ","
End If
Next
SelectedID = Left(SelectedID, Len(SelectedID) - 1)
Forms![Contact List].Filter = "ID In (" & SelectedID & ")"
Forms![Contact List].FilterOn = True
Else
Forms![Contact List].FilterOn = False
End If
End With
This is working perfectly as long as items are selected.I didn't see you mentioning multi selecting.
Check this
Code:Dim SelectedID As String Dim index As Integer If Not CurrentProject.AllForms("Contact List").IsLoaded Then Exit Sub With lbSearchResults If .ItemsSelected.Count > 0 Then For index = 0 To .ListCount - 1 If .Selected(index) Then SelectedID = SelectedID & .Column(0, index) & "," End If Next SelectedID = Left(SelectedID, Len(SelectedID) - 1) Forms![Contact List].Filter = "ID In (" & SelectedID & ")" Forms![Contact List].FilterOn = True Else Forms![Contact List].FilterOn = False End If End With
Ah OK, that's a bit different!Did I make sense?![]()
Dim SelectedID As String
Dim index As Integer
If Not CurrentProject.AllForms("Contact List").IsLoaded Then Exit Sub
With lbSearchResults
For index = 0 To .ListCount - 1
If .ItemData(index) Then
SelectedID = SelectedID & .Column(0, index) & ","
End If
Next
If SelectedID = "" Then
Forms![Contact List].FilterOn = False
Else
SelectedID = Left(SelectedID, Len(SelectedID) - 1)
Forms![Contact List].Filter = "ID In (" & SelectedID & ")"
Forms![Contact List].FilterOn = True
End If
End With
My form "Contact List" opens up on db launch and has all contacts in continuous form.Ah OK, that's a bit different!
Just to be sure: you want the original form to be filtered with the results from the filter form (more than one if more than one is returned).
If no results returned in the filter form, then don't filter the calling form
?
YES YES YES!Check this
Code:Dim SelectedID As String Dim index As Integer If Not CurrentProject.AllForms("Contact List").IsLoaded Then Exit Sub With lbSearchResults For index = 0 To .ListCount - 1 If .ItemData(index) Then SelectedID = SelectedID & .Column(0, index) & "," End If Next If SelectedID = "" Then Forms![Contact List].FilterOn = False Else SelectedID = Left(SelectedID, Len(SelectedID) - 1) Forms![Contact List].Filter = "ID In (" & SelectedID & ")" Forms![Contact List].FilterOn = True End If End With
Dim SelectedID As String
Dim index As Integer
If Not CurrentProject.AllForms("Contact List").IsLoaded Then Exit Sub
With lbSearchResults
For index = 0 To .ListCount - 1
SelectedID = SelectedID & .Column(0, index) & ","
Next
If SelectedID = "" Then
Forms![Contact List].FilterOn = False
Else
SelectedID = Left(SelectedID, Len(SelectedID) - 1)
Forms![Contact List].Filter = "ID In (" & SelectedID & ")"
Forms![Contact List].FilterOn = True
End If
End With