« USE IN SELECT(
August 12, 2008
Employ SQL-SELECTs "TO SCREEN" clause to determine if a record exists
To determine if a record exists in a table, I used to send the results of a SQL-SELECT to an array, like so:
LOCAL ARRAY la[FieldName][1]
_Tally = 0
SELECT [FieldName] ;
FROM [Database]![TableName] ;
WHERE [FieldName] = [Memory Variable] ;
INTO ARRAY la[FieldName]
IF _Tally = 0
MESSAGEBOX(TRANSFORM([Memory Variable]) + ' is not a valid [Whatever] ',
0, '[MESSAGEBOX() Caption]')
ENDIF
Sending the results of the SQL-SELECT TO SCREEN NOCONSOLE obviates the need to declare an array prior to doing the SQL-SELECT:
_Tally = 0
SELECT [FieldName] ;
FROM [Database]![TableName] ;
WHERE [FieldName] = [Memory Variable] ;
TO SCREEN NOCONSOLE
IF _Tally = 0
MESSAGEBOX(TRANSFORM([Memory Variable]) + ' is not a valid [Whatever] ',
0, '[MESSAGEBOX() Caption]')
ENDIF
In different versions of VFP up to and including VFP 8, _Tally was not always reliably accurate (cf. http://foxproadvisor.com/doc/12139 [Cathy Pountney's "_TALLY trap tip]); if that is your experience, simply send the output to a CURSOR and then check the RECCOUNT() of the cursor.
Enjoy!
Art Bergquist
Posted by abergquist on August 12, 2008 | Permalink
TrackBack
TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d8341fba8753ef00e553fca91d8834
Listed below are links to weblogs that reference Employ SQL-SELECTs "TO SCREEN" clause to determine if a record exists:
Comments
HOW I CAN CHANGE IN FOXPRO INVOCING PROGRAM
Posted by: AKBAT | Sep 21, 2010 11:56:36 PM




