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

Removing a single record from a buffer 2

Status
Not open for further replies.

markftwain

Technical User
Jul 12, 2006
108
Hi experts,

Details:
A table is optimistically buffered. Multiple records have been read and inserted into the buffer. Some of those records are new to the table and some have been modified. Ooops, one of the new records is a mistake.

Can only the "mistake" record be removed directly without a delete-tableupdate-pack sequence or affecting the other records?

Thank you
 
Yes, you move to that record and do a single record revert via Tablerevert(.f.)

Bye, Olaf.
 
Actually a delete of that record in the buffer is a good first step, even though such records would also be stored into the dbf then. But this means the fldstate of that record will be 4 in regard of the deletion status, which means new record, but deleted again already.

Assume you have a table called tblAlias and have new records in it's buffer you deleted before and are at the point you want to save via tableupdate(), then you can revert all those records this way:

Code:
Local llDeleted, lnRecord

llDeleted = (Set("Deleted")="ON")
Set Deleted Off
lnRecord = GetNextModified(0,"tblalias")
Do While lnRecord>0
   If GetFldState(0,"tblAlias")=4
      TableRevert(.f.,"tblAlias")
   Endif
   lnRecord = GetNextModified(lnRecord,"tblAlias")
EndDo
If llDeleted 
   Set Deleted On
Endif
[code]

This way you don't store new but unwanted records into the dbf.

Bye, Olaf.
 
Note that, as written, that code won't do what you want.

Add a GOTO lnRecord as the first statement after DO WHILE.

GetNextModified() returns a record number, but does not go to that record.
 
Thanks, dan.

And as another side note: There also is sample code in the GetNextModified() help topic.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top