How To Filter Form I Am In

B

Bgreer5050

I have a form: MainForm
I have a blank unbound text box on the form: findwo
I have number field:WorkOrder
I have a command button:Find

I would like to run a macro for the click event of the find button to apply
a filter to find the record that matches has a WorkOrder value that matches
the unbound textbox value.

Please help.

Thanks
 
A

Allen Browne

1. Set the On Click property of your Find button to:
[Event Procedure]

2. Click the Build Button (...) beside this property.
Access opens the Code window.

3. Set up the event procedure code so it looks like this:

Private Sub Find_Click()
If Me.Dirty Then Me.Dirty = False 'Save record first.
If IsNull(Me.findwo) Then
Me.FilterOn = False
Else
Me.Filter = "WorkOrder = " & Me.findwo
Me.FilterOn = True
End If
End Sub


If you want a solution that lets you choose any field on your form to filter
on, and applies the filter with each keystroke, see:
Find as you type
at:
http://allenbrowne.com/AppFindAsUType.html
 
B

bgreer5050

How do I remove the filter using another button "RemoveFilter" ?

Thanks

Allen said:
1. Set the On Click property of your Find button to:
[Event Procedure]

2. Click the Build Button (...) beside this property.
Access opens the Code window.

3. Set up the event procedure code so it looks like this:

Private Sub Find_Click()
If Me.Dirty Then Me.Dirty = False 'Save record first.
If IsNull(Me.findwo) Then
Me.FilterOn = False
Else
Me.Filter = "WorkOrder = " & Me.findwo
Me.FilterOn = True
End If
End Sub


If you want a solution that lets you choose any field on your form to filter
on, and applies the filter with each keystroke, see:
Find as you type
at:
http://allenbrowne.com/AppFindAsUType.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Bgreer5050 said:
I have a form: MainForm
I have a blank unbound text box on the form: findwo
I have number field:WorkOrder
I have a command button:Find

I would like to run a macro for the click event of the find button to
apply a filter to find the record that matches has a WorkOrder value that
matches the unbound textbox value.

Please help.

Thanks
 
A

Allen Browne

Turn off the form's FilterOn property:

If Me.Dirty Then Me.Dirty = False 'Save record first.
Me.FilterOn = False

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

How do I remove the filter using another button "RemoveFilter" ?

Thanks

Allen said:
1. Set the On Click property of your Find button to:
[Event Procedure]

2. Click the Build Button (...) beside this property.
Access opens the Code window.

3. Set up the event procedure code so it looks like this:

Private Sub Find_Click()
If Me.Dirty Then Me.Dirty = False 'Save record first.
If IsNull(Me.findwo) Then
Me.FilterOn = False
Else
Me.Filter = "WorkOrder = " & Me.findwo
Me.FilterOn = True
End If
End Sub


If you want a solution that lets you choose any field on your form to
filter
on, and applies the filter with each keystroke, see:
Find as you type
at:
http://allenbrowne.com/AppFindAsUType.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Bgreer5050 said:
I have a form: MainForm
I have a blank unbound text box on the form: findwo
I have number field:WorkOrder
I have a command button:Find

I would like to run a macro for the click event of the find button to
apply a filter to find the record that matches has a WorkOrder value
that
matches the unbound textbox value.

Please help.

Thanks
 
Top