SelectWithin in procedure SelectsAll

Using SelectWithin to further qualify a selection in a procedure. In the event there are no records matching the “SelectWithin”, PanX does a SelectAll, instead of doing nothing, which would seem like the logical result. Is this a feature? If so, what’s the best way to leave records untouched?

By first using the startdatabasechange statement and then, by following your selectwithin statement with the checkemptyselection statement, you will get a warning if the selection was empty and the previous selection will be reselected.

startdatabasechange "allrecords","Undo Selection"
selectwithin MyField contains "Tom Thumb" 
checkemptyselection

Ok, I just tested a method to do the same thing as using the checkemptyselection statement but without having a notice appear.

startdatabasechange "allrecords","Undo Selection"
selectwithin MyField contains "Tom Thumb
if info("empty")
    sendaction "undo:"
endif

Thanks, Gary. That will work just fine!
I think I must have dozed off during the intro to the “startdadabasechange” and “checkemptyselection” sections, as I wasn’t aware of their use until now. Pretty slick. Nevertheless, resorting to the “send action” still seems a bit edgy. :wink:
Seems like a switch on the “checkemptyselection” statement could more easily turn the alert off/on. (?)

Actually the sendaction "undo:" is not edgy at all. If you look at the code for the checkemptyselection you will find:

if info("empty")
    nsnotify "No records selected!","TEXT","Reverted to previously selected records."
    sendaction "undo:"
endif

So it is using the exact same code as I suggested but only adding the nsnotify warning.

Ah! I was only referring to the rather stern warning from Provue, in the “sendaction” docs in help file, that the command was unsupported, etc.
Thanks, Gary. :wink:

This is a very “Retro” method that doesn’t use the new PanX tricks - but it might be handy sometime. I usually create a spare text/date/numeric field/s in a database because they often become useful along the way. In this case, you could fill a spare text field with some “marker” character (for example, “X”) after a successful selection and if your WithIn results in a SelectAll (because result was empty), you could get back to previous by selecting on your marker field. Of course there is some maintenance in deciding when to clear that field.

You will have to issue another select but it is a simple (one comparison) selection and saves time if you are several selections deep before running into a “none found” situtation.

In Pan 6, SelectWithin would revert to the previous selection if it failed to select anything. info(“Empty”) provided an opportunity to reliably take alternative actions.

As has been discussed here, that’s not the case in Pan X. checkemptyselection works to restore the selection and if followed by info(“empty”) that code runs. Similarly, info(“Empty”) followed by sendaction “undo:” restores the original selection.

But an effort to make a different selection doesn’t seem to run at all

In a selection of records SelectWithin Date ≥ date(“3/1/21") selects 10 records. If I use a date that has no results, the selection fails and I’m able to return to the original records where I’d like to try again. But I can’t get another try to work.

In the procedure below, the first selection fails and the original set of records is restored. Info(“Empty”) is running because I get the X message but those 10 records that are among the current set are not being selected. If I change to a successful date on the first selectwithin, the X message never appears. So it seems that subsequent searches are not taking place.

startdatabasechange "allrecords","Undo Selection"
SelectWithin Date ≥ date(“5/1/21") 
checkemptyselection

If info("Empty") = -1
    SelectWithin Date ≥ date("3/9/21")
    Message 'X'
EndIf

Message "onward"

Try adding a Wait 0 statement just above the second selection:

startdatabasechange "allrecords","Undo Selection"
SelectWithin Date ≥ date(“5/1/21") 
checkemptyselection

If info("Empty") = -1
    Wait 0
    SelectWithin Date ≥ date("3/9/21")
    Message 'X'
EndIf

Message "onward"

Seems like it’s the second “SelectWithin” that’s not working, as things seem to work ok if you change that one to “Select”. Haven’t tried “SelectAdditional” yet.