The safeselectwithin statement makes visible only those previously selected records in the active database for which the specified condition is true. If no records match, the previous selection is retained.


This statement has one parameter:

condition – is a Boolean formula (a formula with a true/false result).


This statement is identical to the selectwithin statement, except that if no records match, the safeselectwithin statement will retain the previous selection (instead of selecting all records). If you don’t care about preserving the previous selection, the selectwithin statement is faster (especially if you are working with large databases and/or a complicated selection formula).

For example, consider a database with items of various prices. Suppose you run code with two consecutive selections.

select Category = "Tools"
selectwithin Price > 200

If the database contains tools, but no tools over $200, the result of this code will be that all records are selected.

Suppose instead you use safeselectwithin for the second selection.

select Category = "Tools"
safeselectwithin Price > 200

With this code, you will be left with all tools selected. (It’s not necessary to use safeselect for the first selection, unless you need to preserve whatever was selected before this code was running.

Like the select statement, you can use the info(“empty”) function to find out whether or not any data was actually selected.

select Category = "Tools"
safeselect Price > 200
if info("empty")
    alertsheet "No tools over $200"

The safeselectwithin statement will also cause Panorama to skip any following bulk modification statements if the selection is empty. See Handling Empty Selections in Code to learn more.

Technical Note: This statement works by first scanning the database to see if any records match the specified formula (only previously selected records are scanned). If not, the data is not touched. If there is at least one matching record, it will go ahead and scan again to do the actual selection. In the worst case, Panorama will have to scan the entire database twice (depending on the location of the first matching record). This “double scan” is why this statement is slower than the regular selectwithin statement. But for small to medium sized databases, the performance difference will not be noticeable.

See Also


10.2NewNew in this version.