Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filter ListBox

Status
Not open for further replies.

cneill

Instructor
Mar 18, 2003
210
GB
Hi I am using the following code so that I can filter the main form based on various unbound text boxes
Example of Filter code

Dim strWhere As String
more code
If Not IsNull(Me.txtFilterScheme) Then
strWhere = strWhere & "([Scheme] Like ""*" & Me.txtFilterScheme & "*"") AND "
End If

If Not IsNull(Me.txtFilterPhase) Then
strWhere = strWhere & "([Phase] Like ""*" & Me.txtFilterPhase & "*"") AND "
End If
More code
Me.Filter = strWhere
Me.FilterOn = True

Now I have a sub form so before I End Sub I have added

Me.SubFrmKAMElectricalTotalsFilterd.Form.RecordSource = "QryKAMElectricalTotalsFiltered"
Me.SubFrmKAMElectricalTotalsFilterd.Form.Filter = strWhere
Me.SubFrmKAMElectricalTotalsFilterd.Form.FilterOn = True
This works
What I would like to do is use a ListBox not a subform, is there a way of doing this as I don't see a Filter in the Properties of a ListBox.

Thanks for your help

CNEILL
 
You can modify the entire Row Source property of the list box.
Code:
Dim strWhere As String
Dim strSQL As String
more code
If Not IsNull(Me.txtFilterScheme) Then
  strWhere = strWhere & "([Scheme] Like ""*" & _
        Me.txtFilterScheme & "*"") AND "
End If
If Not IsNull(Me.txtFilterPhase) Then
    strWhere = strWhere & "([Phase] Like ""*" & _
         Me.txtFilterPhase & "*"") AND "
End If
More code
strSQL = "SELECT ... FROM ... " & strWhere & _
    " ORDER BY ..."
Me.lboYourName.RowSource = strSQL


Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top