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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to go to a specific record in a Grid

Status
Not open for further replies.

VictorFRodriguez

Programmer
Jan 20, 2001
51
DO
When I open a form with a grid in it, I want the position of the cursor to be in a specific record based on today's date, but always goes on top.
What should I do ///?
Victor F. Rodriguez
 
You can index the cursor if it is readwrite type. Then set the order to the TAG name (index name) and use ascending or descending order. It is simple to send the pointer to the top by doing the GO TOP command.

INDEX ON Date_field TAG datefield

** then:

SET ORDER TO datefield descending

** or -

SET ORDER TO datefield ascending

GO TOP
 
PS if you want to point to say a specific key field or say item number then index that field and use the SEEK() command. IE:

** Create an index to allow seek (very fast)
INDEX ON Item_id TAG itemid

** Use seek to find value from form variable
SEEK(ThisForm.lcItemId)

** Now if the SEEK() was TRUE then the pointer will be on the found record. Keep in mind you should be using unique data for an indexed field for accuracy.
 
Hi Victor,

In addition to Robs' answer above, as the date you are looking for may not exist in the table I suggest that you do your inital seek with NEAR set on... so in the INIT method of your form:

Code:
select 0
use MyCursor  && or do a sql to get it
Index on DTOS(MyDateField) TAG DateOrder
Set Near On
Seek DTOS(MyChosenDateValue)
Set Near Off



Regards

Griff
Keep [Smile]ing
 
Rob,

I agree with eveything you say, except for one small point:

You can index the cursor if it is readwrite type.

I might be wrong, but I believe that a cursor does not have to be readwrite in order to be indexed.

Mike


Mike Lewis
Edinburgh, Scotland
 
Mike Lewis

You are correct, a cursor created with an sql statement can be indexed, but can only have one index (make it the good one).

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Victor,

If you are using a SQL statement to create the cursor, why don't you add 'order by <datefield> desc' clause.

Foxbldr
 
The advantage of having an index is speed and the ability to quickly move the pointer to a different record. I find it much easier to simply add READWRITE to the end of the query so I can add more than 1 index.

SELECT * FROM myTable into CURSOR CmyTable READWRITE
INDEX ON Date_field tag datefield
INDEX ON Customer_name tag custname ADDITIVE

Keep in mind that readwrite is only avaliable in Fox 7 and higher.
 
Hi,

SELECT * FROM myTable INTO CURSOR myCursor

Now assuming the myTable have few index tags...
SET ORDER TO 1 or 2 or 3.. wlll use the parents index but work on the cursor. There is no need even to index in this case.

Mike Gagnon and MikeLewis,

SELECT a.fld1, b.fld2 FROM ... a,b ;
WHERE ... INTO CURSOR myCursor

INDEX ON fld1 TAG fld1 OF myCursor
INDEX ON fld2 TAG fld2 OF myCursor
This will perfectly work. No limitation as to 2nd TAG.

:)


ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com

 
Hi Foxbldr,

ORDER BY class will only set the sorting by that order.You cannot do a SEEK which needs an index. :)


ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com

 
Hi Ramani,

Yes, you are correct. I thought Victor wants to move the cursor to the record with the latest date.

Foxbldr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top