To filter records on a form.
- Works on a sub form
- DoCmd.applyfilter on a subform (DOES NOT WORK)
Filter using a STRING value
- Me.Filter = "[COMPANY] = '" & StrCoSearch & "'"
- Me.Filter = "[Rpt By]='" & StrUserSearch & "' And [COMPANY]='" & StrCoSearch & "'"
Filter using a FIXED value
- Me.Filter = "[Status] = '6-HELP'"
- Me.Filter = "[Status] <> '3-CLOSED'" '(NOT LIKE a Value)
Filter using a INTEGER (NUMBER) value
Example
Dim IntValueYR As Integer
If IsNull([Filter_Year]) Then Exit Sub 'If the form field is NULL, then just exit the Sub Routine ELSE carry on
IntValueYR = [Filter_Year] 'Sets IntValueTR to a value on the form, in this case [Filter_Year]
Me.Filter = "Yr =" & IntValueYR ' Sets the filter to where the field on the form YR is = to IntValueYR
Me.FilterOn = True 'Applies the filter
ME.FILTER
- https://docs.microsoft.com/en-us/office/vba/api/access.form.filter%28property%29
- Me.Filter = "Country = 'USA'" Me.FilterOn = True
- https://docs.microsoft.com/en-us/office/vba/api/access.form.filter(property)
How to Handle Null values with filters
Help Links
- https://www.accessforums.net/showthread.php?t=81499
- https://www.access-programmers.co.uk/forums/threads/using-a-variable-with-docmd-applyfilter.53285/