At the beginning of your script your script check for the number of records. If there are none exit the script.
It sounds like you need to capture a 'no records found' (401 error code) condition and add an exit to the script for the 401 error. If you post your script it would be easier to see where you would need to place the condition or if there is some other issue.
Also try the following resource just in case the above is not on the mark:
Thanks all for you quick response and suggestions. I finally had to alter my script to supress on the OnLayoutExit trigger. It worked but, not without much trial and error. Thank you again for your quick response.
If [ $$ldOnLayoutExitTrigger = "TriggerDisabled" ]
Set Variable [ $$ldOnLayoutExitTrigger; Value:"" ] Exit Script [ ]
If [ IsEmpty ( fmpLessonDetails::clDate ) or IsEmpty ( fmpLessonDetails::clStudentID ) or IsEmpty ( fmpLessonDetails::clCodeID )
or IsEmpty ( fmpLessonDetails::clQuantity ) ]
Show Custom Dialog [ Title: "Lesson Details"; Message: "Please enter all required information."; Default Button: “OK”, Commit: “Yes” ]
Exit Script [ Result: False ]