Filter By Selection Button on Form (1 Viewer)

naminder

Registered User.
Local time
Today, 20:22
Joined
Aug 8, 2005
Messages
41
Hi, I am trying to find code that will let me put a command button on a search form. When it is clicked I want the command filter by selection to filter the records. Basically copying the command when you click the button on the toolbar :rolleyes:
 

Oldsoftboss

AWF VIP
Local time
Tomorrow, 05:22
Joined
Oct 28, 2001
Messages
2,499
Try:

DoCmd.RunCommand acCmdFilterBySelection

when you type "DoCmd.RunCommand", after pressing the space bar, a list of members of the group. Another way is to search the object browser by typing accmd to the search box. A list of all members will be displayed.

Dave
 

naminder

Registered User.
Local time
Today, 20:22
Joined
Aug 8, 2005
Messages
41
hi there!

cheers for that. Im using Access 2003 and that code throws errors. saying can't find. figured it was something to do with setfocus. Anyway code below sorted it!!!

Private Sub cmdFilterSelect_Click()
On Error Goto ErrHandler
Screen.PreviousControl.SetFocus
DoCmd.RunCommand acCmdFilterBySelection
Exit Sub
ErrHandler:
Select Case Err.Number
Case 2046 'Filter not available at moment
MsgBox "Command not available"
Case Else
MsgBox Err.Number & vbCrLf & Err.Description
End Select
End Sub
 

kanikedude03

New member
Local time
Today, 12:22
Joined
Jul 9, 2007
Messages
1
Can't get this to work

Hello, i'm trying to get this to work also. I tried the code posted and it throws up an error with both sets of code. I'm using Access 2003. Any idea what i might be doing wrong? I added a command button, went to build event, Code Builder, then pasted the code. I just need to know what i'm doing wrong. Thanks everyone.
 

eirman

Registered User.
Local time
Today, 20:22
Joined
Aug 16, 2013
Messages
38
With the built-in Filter By Selection tool on the ribbon/toolbar, you can filter by selection on PART of a field.

In this example field [THE BIG BLUE HOUSE]
With the Filter By Selection Tool you can search for BIG or BIG BLUE.

However, naminder's code works by filtering By Selection of the whole field.

Could someone improve the code so that it emulates built-in Filter By Selection tool.

(I'm using Access 2013)
 

Users who are viewing this thread

Top Bottom