Username:
Password:
FileMaker Pro 9: Advanced Tutorials

Ultimate Find / No Find Criteria

Subtitles of the Movie

When you turn on Set Error Capture you have a great responsibility to know all the possible errors that could occur, otherwise you could have disastrous results. Let's say you didn't know that an error was going to occur in a script that had a Delete All Records. It's possible that by not identifying that error it could show all records and delete every record in your database, rather than the couple of records you had planned on having it delete. Now, it's not quite that disastrous inside our Find script, but let me show you what could happen. If we go into Find mode, don't type any find criterion, and just click the find button, we get this different message; this is: No find criteria entered. Now if we run this in our script and just click continue, we get absolutely no error message and this can be confusing. They might think that they entered some criteria and that this is what they found, or who knows what. It's just confusing. You should let them know, Hey, you're supposed to enter Find criteria here, you didn't and we didn't do the find. So, let's go into ScriptMaker, we'll locate our Ultimate Find script and many times so far in the preceding Chapters in the previous tutorial, we went ahead and checked for errors. We showed you how to use a Show Custom Dialog with Get Last Error in there right after where the error occurs to find out what that error number is. We've done that many times so we're not going to do it again. What we're going to do is tell you that no find criteria is an Error 400. So, all we have to do is come in here and Say Else-If Get last error equals 400, and then we can show Custom dialog. No Find criteria. No find criteria was entered. You will be taken back to data entry. There you go. Get rid of the cancel, click OKay, and you don't have to do a Show Records like you did up here because this Finds zero records so you don't want to have that happen, but in this case what actually happens is it takes you back to the found set that you had before you started the find, so that's actually a great result. We like that because it's really the same as if you hit the Cancel button and somebody might get the Continue and Cancel mixed up and it would be nice to take them back to their found set. So that works great. So we'll save that. And let's try it. And when I test things and I've made some changes to a script, I usually like to test the things that used to work, just to make sure they're still working. So we'll go through the whole gambit. What if we do locate something: John. That works great. We find three. What if we type in something they can't find: click OKay, and then, now let's try No Find Criteria. So what happens, we get no error message, so let's look at our script and find out why. And we'll go down to our Ultimate find script and you might think it has something to do with this L sys statement, and that's not really where the problem is, although it kind of is. What the problem really is, is much bigger. It's, it's explained by looking at how errors work in FileMaker. So here's where we turn on Set Error Capture. When we run the set variable it's very unlikely to produce an error therefore it produces an error of zero, and that's placed in memory. Then we move down to go to layout which is also unlikely to produce an error. That produces zero and replaces the zero that was placed in there by set variable. Go down to Enter Find mode; that's unlikely to create an error. Zero replaces this zero, and so on, until we get down here and Perform Find can produce a 401, a 400 or a zero. So let's say I produced a 400. It would come down to being a statement saying, 400 equals 401, false? So it steps down here, and then it goes zero equals 400. It doesn't say 400 equals 400 and that's because when you ran the script step it produced an error of zero, erased the 400 that was created here, and so when it gets down here its actually got a zero in it now. So put succinctly, script errors are stored for a single script step. Each time you run a script it erases that error that you had and puts in a new one. So, there are several solutions here. We could come up here and take a snapshot like we have in previous scripts. We could put in a set variable, or we could put a set field with a global. We might do something like dollar sign error and then put Get Last Error. And so what this does is takes a snapshot of that error so that when it disappears you still have it in other memory spot that you have full control over. So all we'd have to do is change Get Last Error to dollar sign error and Get Last Error to dollar sign Error down here, and that way we've solved the problem. And this is great. We've used this technique before, but let's try looking at it more creatively. Let's take the set variable out and what I'd like to do here is rearrange this If statement so that we have the 400 up here and the 401 down here. So what are we going to do? We're going to come in here and change this to a 400, change this to a 401, and then we're going to swap these. So we're going to put the Show Custom dialog up here, put the Else-If up here, and now they've been swapped. We still have the same problem. The 400 works, but now the 401 doesn't work. So what do we do? We come down here and use a different Get function: Get Found Count. click OKay, and actually before you do that, make sure we change that to a zero, and so what we're doing is something that doesn't rely on the error memory. We're saying, Well, if we found zero records, in other words, we had a 401, our found count is going to be zero. It's really the same thing as checking for Error 401, and so, we don't have to rely on that being in memory and we've cut out a script step. Anytime you can cut out a script step that's always a great thing because you do it over and over and over, and usually your script gets easier and easier to read because shorter is usually easier. So let's try this out. We'll hit Save, try everything out again; we'll type in John, hit Continue; that looks good. Type in Johnny, hit Continue; no customers are located, that's exactly what we wanted. It shows all records and then we'll simply try No Criteria, we get this message. Now one little thing I'd like to change is you can see actually Browse Mode back here and we can't solve it the same way by relocating the Show records, because they're already showing the same file it says you had before, so we have to take a different approach. We can come in here and very quickly enter Find mode without the Pause, and then enter Browse mode. Just put them on either side of the Show Custom Dialog, and that will give us the same results; essentially the same results. To the user it'll look the same. So, hit continue. You can see that they don't say anything in the background, and then they go back to Browse mode.

Tutorial Information

Course: FileMaker Pro 9: Advanced
Author: John Mark Osborne
SKU: 33824
ISBN: 1-934743-32-1
Release Date: 2007-11-21
Duration: 10 hrs / 115 lessons
Work Files: Yes
Captions: For Online University members only
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 81,350 Video Tutorials (20,800 free)
  • Video Available as Flash or QuickTime
  • Over 782 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available