When creating loops that traverse through all the records of a found set, most all of us use the useful “Go to Record/Request/Page [Next; Exit after last]” function. It’s quite nice, since it prevents a loop from continuing into infinity when you reach the last record of a found set. However, you will always get an Error 101 from this.
Error 101 is telling us that the record we want is not found. For this case, the record we want is the next record, which doesn’t exist because we’re already at the end. You would think the built in function would suppress this error when you select to option to exit after the last record, but the error still gets logged, and will pop-up if we use the debugger window or if we are running a server script.
What can we do?
We we have two choices: ignore the benign error or use another method. I chose the latter, a method that won’t trigger the error.
Is actually quite easy to prevent this error, since it only requires one extra line of code. So until the devs of FileMaker fix this bug, we’ll just have to place the following line of code before the Go to Record function:
Exit Loop If [ Get ( RecordNumber ) = Get ( FoundCount ) ]
When we are at the end of our found set (e.g. record 72 of 72 total) this will tell FileMaker to exit the loop.
Very simple, but still I wish we didn’t have to add this at all.