find button in form

  • Thread starter Thread starter twas
  • Start date Start date
T

twas

I would like to make a button that could be used in a form to find records,
friendly enough that untrained users could make use of the feature.

I would like to create a button that does a "find in form", provided the
user isn't already trying to do a find or filter.

I would like a second button that would apply the filter created when the
user entered data in the "find in form", and a third button that would
eliminate the filter.

In FileMaker Pro, I used one button for the first two functions with a
script that was equivalent to
if not in Find mode, enter "Find by Form" mode;
else perform the find to filter the dataset to matching values.

I know this can be done using the built-in user interface in Access, but it
would be nice to create user-friendly buttons with words rather than symbols
that untrained users do not understand.

It seems easy, but none of my attempts work. Any suggestions?

thanks
Twas
 
When you talk about "Find by Form", I presume you are referring to the
built-in Filter By Form (FBF) button on the toolbar.

It is possible to add a command button to your form, and put this in its
Click event:
RunCommand acCmdFilterByForm
The problem is that you can't add a command button to apply the filter,
because no code runs in FBF. The use must use one of the built-in mechanisms
for applying the filter (such as the toolbar button), so they are probably
better off without the command button in the first place.

If you are interested in how to program your own filtering mechanisms for
your forms, see:
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
This explains how to give the user specific boxes to enter values for the
fields they are likely to want to search on, and filters the form based on
whatever combination the user enters.

For another alternative, see:
Find as you type - Filter forms with each keystroke
at:
http://allenbrowne.com/AppFindAsUType.html
In this one, the user selects what field to search (choosing from a
drop-down list). It then filters the form as they type the value to find.
 
That certainly does explain why I've been unable to find anything that would
apply the Filter By Form.

The links are most useful; I'd seen your Search Form but not the "Find as
you type".

The "Find as you type" seems to have a built-in limitation that the user can
only filter by at most once field, so to match the flexibility in searching
of Filter By Form, I'd probably be better off building a custom filter
Search Form.

thanks
Twas
 
The simplest way is to use Access' built-in find dialog. You can wrap this in
a button with this code:

' This returns focus to the control that had focus before the command button:
Screen.PreviousControl.SetFocus
'This opens the find dialog:
Docmd.RunCommand acCmdFind

This will find records in the selected field. To set the form's filter to
the selected field's value, do something like this in a command button:
Me.Filter = Screen.PreviousControl.ControlSource & "='" &
Screen.PreviousControl.Value & "'"
Me.FilterOn = True

To remove a filter, use:
Me.Filter=""

Barry
 

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