Building a flexible date search in FileMaker Pro

David Head
18 August, 2014
View more articles fromthe author

This is an intermediate technique that assumes you know how to create global fields and scripts.

You may have seen our Hints and Tips article about searching for dates using FileMaker Pro. But what if you don’t want to teach your users how to search for dates? How can you provide a flexible search utility for users searching on a date field?

Let’s define the user requirements first. Our users need a simple button to run a search on a specific date field and we want to provide the option for them to search for one date or a date range. This will be done through a custom dialogue allowing the entry of one or two dates.

The custom dialogue box will populate global date fields in the table. In this example, two global date fields have been created called searchDate1 and searchDate2.

The script needed looks like this:

This basic script will do the job. However, there are a couple of areas where it should be improved. Firstly, the first date field in the custom dialogue must not be left empty. So we trap for that with an If statement testing IsEmpty (Invoices::searchDate1) and exiting the script with a message for the user.

Secondly, if the performed find results in no found records, the existing error capture will suppress the standard FileMaker error message. You may want to insert a custom message advising no records were found that match the search using an If statement testing for Get (FoundCount) = 0.

Here is a modified script with the additional scripting highlighted:

Modified Script

At an advanced level, you could abstract the field being searched by constructing the find request using the Set Field by Name script step and specifying the field name with a script parameter when calling the script. In this way, the same script could be used to search different date fields.

Leave a Comment

Please keep your comments friendly on the topic.

Contact us