Username:
Password:
FileMaker Pro 9: Advanced Tutorials

Ultimate Find / Modify Find

Subtitles of the Movie

Our Find script is getting pretty good, but there's something I'd like you to do that a manual find can do pretty well. So let's go into Find and let's enter in something it can't locate. Then we'll hit the Find button and you get this message. Now before we hit Cancel, but if we hit Modify Find, it allows you to change your find criteria and then perform the Find again so you can notice where your mistake is, re-define your Find criteria and perform a successful Find. I'd like to add this to our script. Let me show you where. We type in something it can't locate. I'd like to have another button, one that will say, Re-define, or Modify my Find Criteria and the other choice will be, No, I don't want to do that. Just take me to data entry. So, let's go into ScriptMaker and we'll locate our Ultimate Find, and the central idea here is to loop all the steps and we won't stop looping until we've found some records, the user decides not to modify their Find criteria and clicks Go Back to Data Entry, or when the error is 400 and they didn't enter anything. Otherwise if the person keeps on clicking Modify Last Find from this Show Custom Dialog, which will add, it should keep looping. So, we're going to add the loop script in here, put one up there and one down here, and we have to decide, we don't really need to loop everything, and we'll start down here at the bottom. We don't need to loop Go to Layout, Original Layout; that's for our results. If we result in something, whether it's I don't want to keep modifying the last find to I found some records, we need to go to the original layout, but that doesn't have to happen every single time. And the same is true up here. We don't need to keep turning on Allow User Abort, or Off Allow User Abort because it only has to happen once. I mean it wouldn't make a difference, but it's pointless to run it over and over. Same with Set Error Capture. Turn it on or off once. That's good enough for the whole script. Set Variable only needs to happen once, and it could actually cause a problem if you set that last layout inside the loop because you might not be on that layout where you started, in fact, you won't be. You'll be on the Find layout, and so I actually messed things up. You also don't want to keep going to the Find layout, although you could, it just really doesn't make sense; you'll be there. And then, here's where we stop. We'll put Enter Find Mode outside the loop because Enter Find Mode gives you a black slate to search on. No Find Criterion there. It's blank. Everything's, and you start from scratch. But we're going to take the Pause off, then inside the loop we're going to use a step called Modify Last Find. We'll move it in there and Modify Last Find says, Take me to Find Mode but with the Find criteria I last searched on. So, in other words, the first time we run the script we'll enter Find mode, but then we'll be inside the loop and looping through here, so the second and the third, and the fourth time we're going to be modifying the last find. And actually we'll do it the first time, but the first time we enter into the loop it's actually going to generate an error because we'll be in Find Mode. We can't actually perform or modify Last Find when in Find Mode; it's only available in Browse mode, but the next time we loop we'll actually be in Browse mode, so Modify Last File will work the second, the third, the fourth, and the fifth. The reason the first time it doesn't show an error is because we have Set Error Capture turned on. So this actually works out really well in this structure here. And then we also have to follow this up with a Pause Resume Script. So enter Find mode the first time, enter the loop, Modify Last Find does nothing, Pause. Come back up. We don't do an Enter Find mode, Modify Last Find, Pause, so we're going to get this. As long as we keep it looping, we'll be able to modify our find criteria as many times as we want. Now we need to go in and modify our custom dialog here. We'll put in something different here: "No Customers located, would you like to modify your find criteria?" and we'll say either yes or no. Now we also have to figure out whether we're going to exit or not, so we'll put an Exit Loop If in here and we'll say, Get Last Message Choice equals two. In other words, if they click the no, which is button number two; Exit. If they click number one, well then skip this exit loop and loop back up and do the modify last find. Now we also need to exit if we get ah, get last error equals 400. So put an Exit loop up here, but it's a very different formula, and it's very simple. Just put a one in here. It can be a little confusing, but essentially one always results in true. So, if it gets into this part of the If statement, in other words, last error equals 400, it'll do this step, this step, this step, and then automatically exit the loop because we're not giving them any choices on what to do, we're just taking them back to data entry. So, this just automatically exits the loop and is controlled by this 400 here. And we also have to duplicate this because we need it one more time; it'll be down here. And we're going to put an Else here; that's because if the last error's 400 if the last error's 401; if neither of these are true then it must be that you found records, therefore we need to exit loop. So this is your I-found-some-records exit loop. So, let's try this out. We'll hit save, hit Find, type in something it can locate; try all three scenarios; that looks good. We'll put nothing in there. Get the right message; good. Hit Find, type in something it can't locate. Get the right message; we'll hit No and make sure that works. Looks good. Type it in again, hit Continue, hit Yes this time. We see Johnny there, we can come in there and modify that and hit Continue and then it goes and finds it for us. So that looks like it works perfectly. Now, I've seen several people in their find scripts, they used Perform Script, and essentially they'll say, Perform script Ultimate Find, so it's a recursive script. Well, it'll work, but what you're doing is you're loading the same script in memory over and over and over again, and there's a certain point at which it could crash because you're going to get a memory overload. So, don't use Perform Script for some type of recursive script. This loop is much better, even though it may be a little bit more complicated; you're not going to have any problems with it.

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