NILKAMAL


hi!

i am new in vfp here is my problem when i delete it delete first record in table not which i view (or currant record)

here is code

#DEFINE MSGBOX_YES 6
#DEFINE C_MSGBOX1 36
#DEFINE C_DELETE1_LOC "Are you sure you want to delete this customer - "
#DEFINE C_DELETE2_LOC " "
lcMessage = C_DELETE1_LOC + ALLTRIM(CHECKCUST.First_NAME) + C_DELETE2_LOC
lcLAST_NAME = CHECKCUST.lAST_NAME

IF MESSAGEBOX(lcMessage,C_MSGBOX1) = MSGBOX_YES
USE customer Exclusive
DELETE
IF !EOF()
SKIP 1
ENDIF
IF EOF() AND !BOF()
SKIP -1
ENDIF

PACK
THISFORM.Refresh
ENDIF




Re: delete currant rec

CetinBasoz


1) With this code you're always deleting the first record in customer table and I'm not sure it's what you wanted to do.

2) Do not pack with each delete. Pack should be reserved to maintanence routines. Instead use 'set deleted on' to hide deleted records.

Normally 'delete current record in some open table' syntax is:

delete in 'aliashere'

For example:

use customer in 0 && open customer table in first available workarea - by default its alias is 'customer'

go 5 in 'customer' && move pointer to record 5 of customer

delete in 'customer' && deletes record 5 which is the current record in customer






Re: delete currant rec

NILKAMAL

thanks for your reply

suppose i am entring customer data and i am on rec no 10th and i want to delete rec no 10 but when i delete it delete rec no 1






Re: delete currant rec

hangover

From your code it appears that you are viewing the customer in one table (CHECKCUST) but trying to delete them from another table (CUSTOMER). Unless you can rely on both tables containing details of the same customers in exactly the same order, it would not be reliable to use the rec no to determine which record to delete. Instead it would be better to use a unique reference for each customer, such as the primary key (if you have one), which is common to both tables, e.g.

USE customer EXCLUSIVE

LOCATE ALL FOR customer_id = CHECKCUST.customer_id
DELETE






Re: delete currant rec

Naomi Nosonovsky

Don't re-open the table everytime. Just use the table once, then DELETE command will delete the current record in the currently opened alias. If you want this record to disappear, use SET DELETED ON setting at the top of your code (or in the Load method of the form).





Re: delete currant rec

MarciaAkins

NILKAMAL wrote:

i am new in vfp here is my problem when i delete it delete first record in table not which i view (or currant record)

here is code

#DEFINE MSGBOX_YES 6
#DEFINE C_MSGBOX1 36
#DEFINE C_DELETE1_LOC "Are you sure you want to delete this customer - "
#DEFINE C_DELETE2_LOC " "
lcMessage = C_DELETE1_LOC + ALLTRIM(CHECKCUST.First_NAME) + C_DELETE2_LOC
lcLAST_NAME = CHECKCUST.lAST_NAME

IF MESSAGEBOX(lcMessage,C_MSGBOX1) = MSGBOX_YES
USE customer Exclusive
DELETE
IF !EOF()
SKIP 1
ENDIF
IF EOF() AND !BOF()
SKIP -1
ENDIF

PACK
THISFORM.Refresh
ENDIF

First of all, since you are new to VFP, the best advice that I can give you is to get a copy of

"Fundamentals: Building Visual Studio Applications on a Visual FoxPro 6.0 Foundation" at http://www.hentzenwerke.com/catalog/fund6.htm. It is the best beginners' reference I have ever seen. Even though it was written for version 6, the concepts haven't changed.

Now on to the problems with your code.

The others have pointed out to you that you must locate the record you are trying to delete. However, I take it that this is not a mutli-user system. If it is, you are going about this all wrong. You need to SET DELETED ON and then when you delete a record, all you need to do is move the reord pointer to have the record that is flagged for deletion disappear.

Your PACKing routine should be a maintenance routine that is run when everone is out of the system.






Re: delete currant rec

NILKAMAL

thanks all of u i used set deleted on and it works

and thanks for naomi ( cos u help me a lot since i start to learn vfp )