Access should have a "multi-dropdown box filter" wizard

A

Allen Browne

You need an example to follow?

Dim strWhere As String
Dim lngLen As Long


If Not IsNull(Me.cbo1) Then 'numeric example
strWhere = strWhere & "([SomeNumberField] = " & Me.cbo1 & ") AND "
End If

If Not IsNull(Me.cbo2) Then 'text example
strWhere = strWhere & "([SomeTextField] = """ & Me.cbo2 & """) AND "
End If

If Not IsNull(Me.cbo3) Then 'date example
strWhere = strWhere & "([SomeDateField] = #" & Me.cbo3 & "#) AND "
End If

lngLen = Len(strWhere) - 5 'Without trailing " AND "
If lngLen < 0 Then
MsgBox "No criteria
Else
If Me.Dirty Then 'Save before filter.
Me.Dirty = False
End If
Me.Filter = Left(strWhere, lngLen)
Me.FilterOn = True
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top