Whats the VB Code for the Filter by Selection function?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to apply a filter by selection on a particular field once a search for
a specific piece of information has been done. Rather than using the
toolbars I have created a search facility but now want to filter on the data
I have found thus sorting my records into types that match my search.
 
Try:
RunCommand acCmdFilterBySelection

How do you intend to fire this?
If you use a command button, when you click the button it takes focus, and
there is no "selection" in the command button, so you would also need:
Screen.PreviousControl.SetFocus
 
Allen

My command button sets the focus on the field i want to filter on, searches
for the data I require (obtained via an input box). I then set the focus
again on the field I want to filter on but can't work out the code for
running the filter by selection?

Damian
 
For the process you describe, it might be simpler just to filter the form to
the value.

This example is for a field of type Number:

Dim strWhere As String
strWhere = InputBox("What value?")
If IsNumeric(strWhere) Then
strWhere = "[MyNumberField] = " & strWhere
Me.Filter = strWhere
Me.FilerOn =True
End If
 
Allen

I can't thank you enough for that - it's brilliant.

It works just how I wanted it to and I've been tearing my hair out for over
a day and half trying to make that work.

Thanks again!



Allen Browne said:
For the process you describe, it might be simpler just to filter the form to
the value.

This example is for a field of type Number:

Dim strWhere As String
strWhere = InputBox("What value?")
If IsNumeric(strWhere) Then
strWhere = "[MyNumberField] = " & strWhere
Me.Filter = strWhere
Me.FilerOn =True
End If

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

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

Damian said:
Allen

My command button sets the focus on the field i want to filter on,
searches
for the data I require (obtained via an input box). I then set the focus
again on the field I want to filter on but can't work out the code for
running the filter by selection?

Damian
 

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

Back
Top