This article is a part of a series on Advanced Search Interfaces.
Using a single, global field and a fairly simple script, you can create a search-engine-like interface for searching the contents of a FileMaker Pro database.
Step One: Create a Global Search Field
Create a text field in any table. In the field options, set the new field to use global storage as shown in the figure below.
Step Two: Create the Find Script
Create a script that enters find mode, creates a new search request for each field you wish to search, copies the value of the global search field to each of those fields and performs a find.
- Enter find mode (do not pause or specify find request).
- For each field you want to search, use the “Set Field” script step to copy the value from the new global field.
- Place a “New Record/Request” steps in between each “Set Field” step.
- Perform Find.
Here’s a sample of how the script might look:
Enter Find Mode [ ]
Set Field [ Contacts::First Name; Globals::GlobalSearch ]
New Record/Request
Set Field [ Contacts::Last Name; Globals::GlobalSearch ]
New Record/Request
Set Field [ Contacts::Address Type 1; Globals::GlobalSearch ]
New Record/Request
Set Field [ Contacts::City 1; Globals::GlobalSearch ]
New Record/Request
Set Field [ Contacts::State Province 1; Globals::GlobalSearch ]
New Record/Request
Set Field [ Contacts::Postal Code 1; Globals::GlobalSearch ]
Set Error Capture [ On ]
Perform Find [ ]
Set Error Capture [ Off ]
If [ Get ( FoundCount ) = 0 ]
Show Custom Dialog [ Title: “No Records Found”; Message: “No records matched your search criteria.”; Buttons: “OK” ]
End If
Step Three: Add Layout Objects
You can then place the global field and a search button to call your new script in your list view header, a pop-up window or wherever else you might find it useful.
That’s it! Now the user can simply enter search terms in the search field and click the search button and view their results without ever entering find mode and without knowing which fields to search.
Enhancement – Split Field Searching
One of the shortcomings of this script is that it will only find records that contain all the search terms in a single field. In other words, if you enter “ABC Plumbing Chicago”, it will only find records that contain the words “ABC Plumbing Chicago” all in the same field. If you want to be able to find a company record for “ABC Plumbing” located in “Chicago”, the script would need to split the phrase up and loop through each word. My article, Google-Like Searches In FileMaker – Non-Contiguous, explains a method to accomplish this.
If you have any questions or comments feel free to post a comment below or contact me directly.
25 Comments