Whats the VB Code for the Filter by Selection function?

D

Damian

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.
 
A

Allen Browne

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
 
D

Damian

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
 
A

Allen Browne

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
 
D

Damian

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
 
Top