Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filtered Data

Status
Not open for further replies.

ChrisAgius

Programmer
Sep 27, 2000
51
MT
I set a filter on a Table. But now I have to check if there are any filtered records and I have to return a message if there are no records which passed the Filter.

I used :
SElect Tablename
If Eof()
Messagebox(...)
Endif

But the program did not encountered the EOF() even though no records passed through the filter. It there something to check the results of the filter.

Thanks
 
Chris

lnRecNo = RECNO([TABLENAME])
COUNT TO lnTotal
GOTO lnRcNo

IF lnTotal = 0
[tab]MESSAGEBOX(...)
ENDIF

Chris
 
If you simply add GO TOP (or LOCATE) after your SELECT Tablename, then the IF EOF() check should work as you're expecting it to.

Rick
 
Chris.
When you set a filter it does not take effect until you move the record pointer off the current record. As stated above doing a COUNT , GO TOP will cause the record pointer to move. My favorite trick is

Use xxx
set filter to
goto bottom
goto top
if eof()
= messagebox()
endif
David W. Grewe
Dave@internationalbid.com
ICQ VFP ActiveList #46145644
 
HI!

The best approach here is to use LOCATE FOR .T. command to move record to top of the record set. In case with Go Top, filter is not optimized, with LOCATE it is optimized, so moving record to the top of the record set is much faster.

After that you can check for eof() as suggested already...


Vlad Grynchyshyn
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
Hello.

Just in case: if your table is located somewhere in the network, the commands GO TOP and GO BOTTOM are very network trafic expensive. In this case, the best way to accomplish your task (and works very fine locally, also) is to select into a cursor the records, in the following way:

SELECT COUNT(*) FROM <your_table> INTO CURSOR crAnyName WHERE <filter_expression>
IF _tally = 0 &amp;&amp; you have no records
... some code....
ELSE
.... some code...
ENDIF


This way is lightning fast.

Hope this helps.
Grigore Dolghin
 
Thanks A lot all of you. I simply moved the Record pointer and I worked perfectly.

Regards ,
Chris
 
yet another way...


SET FILTER TO whatever
GO TOP
IF BOF()=.F. AND EOF()=.T. THEN
*no records
ELSE
*there are records
ENDIF

-Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top