Full Version: custom buttons
UtterAccess Forums > Microsoft® Access > Access Forms
I was wondering if there is a way to place on a form buttons that act the same way as the filer by selection, filter by form and apply filter buttons on the toolbar?
Jack Cowley
Give some details on what you would like these buttons to do and I am sure someone will have a suggestion or two...
I think the commands to do those (which you can put behind the CLICK event of your buttons) are:
DoCmd.RunCommand acCmdFilterBySelection
DoCmd.RunCommand acCmdFilterByForm

DoCmd.RunCommand acCmdApplyFilterSort
See also my replies in the UA thread 1071148.
I tried placing those commands (DoCmd.RunCommand acCmd...) on the OnClick event of a button, but when I tried using it, I get the error message:
un-time error '2046':
The command or action 'FilterBySelection' isn't available now.
Any ideas?
I got it working, the error was caused because when you click a button, the focus moves to that button so the filter was generating that error. I just had to set the focus to the previous control. Now there is another problem, however. When the FilterByForm button (on the form, not toolbar) is clicked, all buttons on the form are disabled. I would like to put the ClearGrid and ApplyFilterSort buttons on the form too, but once the FilterByForm button is clicked by the user, these buttons would not be available, is there any way around this?
I am not 100% sure as I don't normally create command buttons for these filter actions but I think for a FilterBySelection to work, the Focus must be on a data-bound Control. When you click the command button trying to do the FilterBySelection action, the command button (a non data-bound Control) has the Focus when the code is executed. Therefore the action is not available and you get the error.
Try adding the statement:
before the DoCmd statement to set the Focus back to the data-bound Control by which you want to perform the FilterBySelection action.
that was strange, good timing Van. Great minds think alike frown.gif
Any ideas how on this other problem?
The second problem was the main topic in the thread I referred to previously. In the FilterByForm action, Access overlays you Form with the FilterForm based on your Form with all CommandButtons removed.
think you will need either a ToolBar with the required actions or a PopUp Form (???) to show the CommandButtons for the required actions when the Form is in the FilterByForm mode.
You're welcome ... Glad we could help ...
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.