button "filter by selection" on a form

G

Guest

I'd like to create a "filter by selection" button on a form with exactly the
same function of the one on the toolbar. I'm using Access 2002. Please make
the explanation as simple as possible. I'm a newbie and I don't know SQL.
Thanks in advance
 
A

Allen Browne

1. In form design view, add a command button to your form, and set these
properties:
Name cmdFilterBySelection
On Click [Event Procedure]

2. Click the Build button beside the On Click property.
Access opens the code window.
Set up the code as follows:

Private Sub cmdFilterBySelection_Click()
On Error GoTo Err_Handler

Screen.PreviousControl.SetFocus
RunCommand acCmdFilterBySelection

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume Exit_Handler
End Sub
 
G

Guest

Great! I made a big step forward with this tip.
It has quite the same function of the button on the toolbar.
The small difference is that, using the one on the toolbar, I can even
select a part of a field in a form as filter item.
The one suggested by you select automatically the whole content of the field.
E.g. I made a query on my database to extract the costs I had last year for
my car, in the "payment" column I'd like to filter "bank check" to show all
these items. With the button on the toolbar I can do it, with your solution
the filter takes the whole field that is "bank check n.xxxxxxx" giving back
only one record.
I hope to have been clear enough. My English need some improvement too.
Thanks for your kind support.


Allen Browne said:
1. In form design view, add a command button to your form, and set these
properties:
Name cmdFilterBySelection
On Click [Event Procedure]

2. Click the Build button beside the On Click property.
Access opens the code window.
Set up the code as follows:

Private Sub cmdFilterBySelection_Click()
On Error GoTo Err_Handler

Screen.PreviousControl.SetFocus
RunCommand acCmdFilterBySelection

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume Exit_Handler
End Sub

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

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

morgan said:
I'd like to create a "filter by selection" button on a form with exactly
the
same function of the one on the toolbar. I'm using Access 2002. Please
make
the explanation as simple as possible. I'm a newbie and I don't know SQL.
Thanks in advance
 
A

Allen Browne

That's correct. When you move to the button on your form, the selection in
the text box is lost, because the button now has focus. When you use the
toolbar, the selection on the form is not lost.

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

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

morgan said:
Great! I made a big step forward with this tip.
It has quite the same function of the button on the toolbar.
The small difference is that, using the one on the toolbar, I can even
select a part of a field in a form as filter item.
The one suggested by you select automatically the whole content of the
field.
E.g. I made a query on my database to extract the costs I had last year
for
my car, in the "payment" column I'd like to filter "bank check" to show
all
these items. With the button on the toolbar I can do it, with your
solution
the filter takes the whole field that is "bank check n.xxxxxxx" giving
back
only one record.
I hope to have been clear enough. My English need some improvement too.
Thanks for your kind support.


Allen Browne said:
1. In form design view, add a command button to your form, and set these
properties:
Name cmdFilterBySelection
On Click [Event Procedure]

2. Click the Build button beside the On Click property.
Access opens the code window.
Set up the code as follows:

Private Sub cmdFilterBySelection_Click()
On Error GoTo Err_Handler

Screen.PreviousControl.SetFocus
RunCommand acCmdFilterBySelection

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume Exit_Handler
End Sub

morgan said:
I'd like to create a "filter by selection" button on a form with
exactly
the
same function of the one on the toolbar. I'm using Access 2002. Please
make
the explanation as simple as possible. I'm a newbie and I don't know
SQL.
Thanks in advance
 

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