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

Reorder Records in Table

Status
Not open for further replies.

SleepDepD

Programmer
Mar 13, 2004
65
US
I'm working in VFP7. I have a simple archiving component in my application that moves records between specified dates from table "A" to table "B". There's also a "recall" functionality (using APPEND FROM DBF) that moves the records back--however this leaves the records in table "A" not in their original chronological order. Is there a way to reorder table "A" based on the date/ID field? Or do I have to use a third table, "C", and delete "A" and rename "C" to "A"?

Appreciate the help.
 
SleepDepD

Unless I am misunderstanding your problem, I would not consider the physical order of reccords, use the index / set order to / sys(22) to arrange the order in which you would like to see your reccords.

Regards,

Koen
 
Oops...left that out: a number of reports/cursors/queries/etc. have been developed by other people on the project who were counting on chronological order; instead of changing all that code it'll just be easier to put the records back in the correct order (how often will they do a recall anyways?)
 
The only way I can see to do this would be to leave table "A" unpacked after you delete the records which are moved to table "B". Then the deleted records can be RECALLed in place.

Jim
 
...kind of defeats the purpose of removing them in the first place.

What I'm thinking of doing is moving all the records back to table "A", apply an index temporarily that will get the records in the order I want, APPEND all the records to another table ("C"), then delete "A" and rename "C" to "A". That will restore the original order.
 
Oh. I thought you wanted to avoid a third table solution.

Jim
 
You mean COPY, not APPEND, right.

Another possible solution.
Code:
RENAME ("A.DBF") TO ("TEMP.DBF")
USE TEMP.DBF EXCLUSIVE
SORT ON SomeField TO ("A.DBF")
USE 
ERASE TEMP.DBF
Regards,

Mike
 
mspratt,

That looks like exactly what I'm looking for. Thanks!
 
You're welcome.

One of the things I really like about VFP. If something can be done, usually there are at least three ways to do it.

Regards,

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top