I am new to using Gambas and am thrilled with it. However, I have run into a problem. I have written a program that contains a textbox into which one enters a unique licence number (ASLNo) eg. 00001. Once the textbox (txtASLNo.Text) loses focus a SQL statement looks for the record associated with the number in a table and loads the returned data into other textboxes etc.
My problem comes when a number is entered and no corresponding record can be found. I want a message to appear stating "record not found" and for the cursor then to return to the ASLNo textbox for a new number to be inserted. To do this I have used the following code:

Dim sSQL as String
Dim sASLNo as string
Dim $rSQLData as Result
sASLNo=txtASLNo.text

Of course there is more code before the above to test whether the number entered is 5 digits long and after the If-EndIf statement, if the record is found the rest of the code processes. All works well when a record is found but when no record is found, the "Record not found" message is generated but then, instead of the cursor going back to the ASLNo textbox the program goes to the CATCH and ERROR message at the end of the program and hangs the program.

The full project is here:
/home/bushbug/AirServiceLicences-0.0.30.tar.gz

It uses a SQLite3 database. Do you require me to post the DB with a few tables filled with sample data?

When running the program, I select the ASLAmend radio button on the Main Form. This opens a form named Amendments. I enter a number (ASLNo) and if the number is not 5 digits long it returns an error message and goes back to the ASLNo text box, selecting the entered text for replacement.

If the number is correct and represents previously saved records in the ASLHolder Table and ASLDates Table, the SQL query finds the record and places the returned data in the various textboxes and Datechoosers.

However, in the event that the number is correct in terms of length but does not represent a number previously saved in the said Tables, the SQL query returns an error message "Record not found! Please enter a valid ASL number" because the DataResult.Index is -1. Then, instead of going back to the ASLNo textbox the process just continues to then edn and throws out an error.

Hi Stevedee,
I have solved the problem by changing the: If DataResult.Index = -1 to <> -1 and placing the Else part after the process. It then works perfectly.
Thank you for your interest and inspiration.
Kind regards,
Frank