SelectWithin in procedure SelectsAll


#1

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?


#2

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

#3

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

#4

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. (?)


#5

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.


#6

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:


#7

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.