Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Want to Code Command button with Filter by Selection and Clear Filter 2

Status
Not open for further replies.

kptasteve

Programmer
Nov 2, 2002
43
US
I would like to create a module for a command button that would filter by selection a continuous form \ then be able to clear the filter using a second command button, and select another field then use the this filter by selection command button again button. I can do this from the tool bar menus buttons but I want to do it on a barless form

Thanks

Steve Marcum PT
Programmer
 
Okay, I have this figured out for you. You will have to make a few updates to the code to reflect form control names but it shouldn't be too difficult. The following is the VBA code for the Filter_By_Selection Command Button:

Private Sub Filter_By_Selection_Click()
On Error GoTo Err_Filter_By_Selection_Click
Dim ctlPrevious As Control
' No previous control error.
Const conNoPreviousControl = 2483
Set ctlPrevious = Screen.PreviousControl
ctlPrevious.SetFocus
DoCmd.RunCommand acCmdFilterBySelection
Exit_Filter_By_Selection_Click:
Exit Sub
Err_Filter_By_Selection_Click:
MsgBox Err.Description
Resume Exit_Filter_By_Selection_Click
End Sub

This VBA code is for the Clear_Filter command Buttons On Click Event Procedure:
Private Sub Clear_Filter_Click()
DoCmd.RunCommand acCmdRemoveFilterSort
End Sub

The following is a must for this to work. You see the Screen.PreviousControl command only works after the focus has moved to two or more controls on the form after it is opened. So, you have to put two control.setfocus commands into the On Open Event Procedure of the form. Just pick a controlname and for the first one and then the second one should be the control that has the first tabstop so that you form looks like it is opening naturally. Then the command buttons will work.

me![ControlName1].setfocus
me![Controlname2].setfocus

Let me know if you need more assistance setting this up. Bob Scriver
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top