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

Need coding assistance

Status
Not open for further replies.

moppsy

IS-IT--Management
Dec 22, 2004
22
US
I have a Visual FoxPro 9.0 application that when a record is deleted it goes back to the first record instead of going to the next record after the deletion. Can anyone give me the code to stay at the next record after a user deletes instead of the program jumping back to the first record. Thanks so much in advance.
 
Moppsy,

Basically you need to save the record number of the next record before you do the deletion to a variable, for example:
Code:
SKIP
NextRecord = RECNO()
SKIP -1
DELETE

You might want to put in a test to ensure that you aren't at the end of file.

After deleting, I would suggest that you execute a line something like:
Code:
GO (IIF(NextRecord<=RECCOUNT(), NextRecord, SomeOtherRecord))
The IIF is to ensure that you avoid a "record is out of range" error. You would need to decide what record to go to and put that in where I've put SomeOtherRecord.

This might seem unneccesary, but I have had that error in exactly this circumstance.


Hope that helps,

Stewart
PS If you want to get the best response to a question, please check out FAQ184-2483 first.
 
With the record pointer on the record to be deleted:
Code:
skip 1
nSaveRecno = recno()
skip -1
delete
go nSaveRecno

Mike Krausnick
Dublin, California
 
Code:
Delete in "MyTable"
Skip 1 in "MyTable"
if EOF("MyTable")
 go bottom in "MyTable"
endif
Thisform.Refresh() && or whatever you need to refresh at this point for the UI

The code above assumes that you have Set Deleted On. I have no idea why your program would be moving the record pointer to the top of the cursor/table. Did you build this with the application wizard or something?

boyd.gif

SweetPotato Software Website
My Blog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top