Username:
Password:
FileMaker Pro 10: Advanced Tutorials

Ultimate Find / Modify Find

Subtitles of the Movie

Our Find script is getting pretty powerful, but there's something a manual Find can do easily that our Find script can't, so let's manually go into Find mode and we'll type in Johnny, something it can't find. We'll hit the Enter key to perform the Find. You can see it allows you to modify the Find. We can click this button, come back over here, change to something else, hit the Enter key, and it actually finds it. So this is a very neat feature I want to add to our script. Let's run our script and see where we'll put this. We'll type in Johnny, click Continue, and remember, Set Error Capture is off so the user won't see this message. We'll hit Continue. Here's the message the user will see. I want to put the button in here, Do You Want To Redefine Your Find Criteria Or Not? We'll give two button choices here. So we're going to go into ScriptMaker. We'll find our script and the basic idea is to add a loop. We're going to add a loop to the beginning and the end. What we're going to do is we're going to keep on looping through all these steps until one of three things happens. Either we've found records, the user doesn't want to modify their Find criteria anymore, or no Find criteria, the error 400 occurs. The only time it will keep looping is when they say I want to redefine. So that's how we do this. now, a lot of people I've seen actually use Perform Script. Instead of looping, they keep calling the same script over and over and over again. It's kind of the same idea, except the Perform script keeps loading that same script into memory and it's possible to get a memory overload and you don't want to do it that way. The loop is much better, even though it's a little more complex to program. So we'll start at the bottom here because not all steps need to be looped. In fact, we only want to go back to the original layout once, once we exit this loop. Now, at the top here, we don't need to keep performing Allow User Abort or Set Error Capture. Those are only things that have to happen once. We don't need to keep setting the variable, dollar sign Last Layout, to remember the last layout, because it really only has to happen once. In fact, it could actually cause a problem. We don't need to keep going to the Find Layout because we'll already be there and here's where we're going to stop. We're going to put Enter Find Mode outside the loop and we're going to take this Pause off and we're going to actually put in Modify Last Find inside the loop. So here's the idea: enter Find mode takes you to Find mode with a blank slate. Modify Last Find takes you to Find mode with the last Find criteria you wanted. So what's going to happen is the first time we run the script, Enter Find Mode is going to clear out the last Find so you can have a blank slate and then Modify Last Find will essentially do nothing because we're in Find mode already, but the second time that they decide to go ahead and redefine their Find criteria, the second time this will run, the third time this will run, the fourth time. Only the first time through will it enter Find mode. Every other time, it'll go from Browse to Find and look at the same Find criteria. So after that, we're going to pause because we took the pause off here, and then we can perform Find like we did, and now we have to decide what are we going to do here? Well, we have to come down to our Show Custom Dialog, our 401 error, and look at it. We need to add another button and change the message, so no customers were located and we'll say Would You Like To Redefine Your Find Criteria? and then we'll have two buttons, Yes and No. There we go. So now we've got the message. Now all we have to do is figure out how to exit the loop. We're going to put it after the Show All Records, Exit Loop If. We'll say Get Last Message Choice equals 2. Not 1, but 2. That's because we want it to exit if they click, no, I don't want to do that. If they click yet, then we want it to go back up and keep looping. So that's where we test whether we get out of the loop or not. We still have some other scenarios, though. What if they enter no Find criteria? Well, we're not giving them a choice. We're just saying okay, so we're going to automatically exit right there. So we're going to use an interesting little Exit Loop If. We'll say Exit Loop If 1. Simple little formula. It's always true. The number 1 is always true, so when it hits this step, it'll automatically exit the loop. Why do we do that? Well, we've already tested for the Last Error Equals 400 and it only can get to this Exit Loop and all the other steps in here if this Error 400 is true. So we don't have to test again. There's no reason to do that. We'll duplicate this because we've got one more test to do. We don't really have a test, actually. We need to Else. This is if we do find one or more records. So if it's not an Error 400, it's not an Error 401, it must have found records. We'll put a little comment here, Found One Or More Records. There we go. That might be a good reminder. You can read it right there. So that looks pretty good. I think we have this thing pretty well taken care of, so let's try it out and test it. So we'll close this, save it, close it, and we want to try all three scenarios again, so we'll try John, hit Continue. Looks good. It did what we wanted. Hit Find again. We'll type in no find criteria this time. We get the error message because Set Error Capture is off. Continue. We get our message. It takes you back here and that's great. We'll hit it again, type in Johnny, click Continue, click Continue again, hit No because we're going to try this button now. It takes us back here. All records are showing. Now we'll try Johnny again, click Continue, Continue. We'll hit Yes this time. You see we can modify our criteria. Hit Continue again. This time it does the Find, so it looks like a great script. It's all working perfectly. It's all the key in the loop there. Keep looping until we don't want to loop anymore. Exit once the user says either I don't want to redefine the Find criteria or they found some records or the No Find Criteria error occurred. Those three scenarios exit the loop; otherwise, don't exit.

Tutorial Information

Course: FileMaker Pro 10: Advanced
Author: John Mark Osborne
SKU: 33927
ISBN: 1-935320-20-3
Release Date: 2009-01-05
Duration: 12 hrs / 150 lessons
Work Files: Yes
Captions: Available on CD and Online University
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