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

How to remove duplicate copy of the table? 2

Status
Not open for further replies.

Mandy_crw

Programmer
Jul 23, 2020
578
PH
Hi everyone... I have been solving this problem for so long...everytime i edit a record in my database using "update" it always makes another cpy of another record but sometimes it does not... what i noticed is that, when i edit a record in a consecutive times, it makes another copy of the record i am edting... so when i edit it for three consecutive times, it creates thee copies of the record edited... Please explain what happened... Thanks and God bless....
 
Hi Mandy,
I gather you're referring to the UPDATE command, right?
Could you post here the entire UPDATE statement here, so we could at least start to analyze the situation?

Regards,

Ilya
 
Mandy,

Could you post the minimum code needed to reproduce the problem. Don't post the entire method or function - just enough so that we can run it ourselves to see what is happening.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Good day everyone... Here are the codes... thanks...

IF FLOCK()

UPDATE TSULAT SET idnum = idnamber, fname = neym, sname = sneym, mobile = mobyle, eadd = eaddress, ;
sex = sexx, status = estatus, strand = estrand, datedit = ddatedit, section = sektion, grant = grand WHERE idnum == idpointer

IF this.Parent.text9.value = 1

DO CASE
CASE this.parent.CboStatus2.value = "Principal"
UPDATE tsulat SET grade = "F", mode = moded, status = estatus, adviser = estatus2 WHERE idnum == idpointer
CASE this.parent.CboStatus2.value = "Coordinator"
UPDATE tsulat SET grade = "F", mode = moded, status = estatus, adviser = estatus2 WHERE idnum == idpointer
CASE this.parent.CboStatus2.value = "Faculty"
UPDATE tsulat SET grade = "F", mode = moded, status = estatus, adviser = estatus2 WHERE idnum == idpointer
CASE this.parent.CboStatus2.value = "Registrar"
UPDATE tsulat SET grade = "F", mode = moded, status = estatus, adviser = estatus2 WHERE idnum == idpointer
CASE this.parent.CboStatus2.value = "Treasurer"
UPDATE tsulat SET grade = "F", mode = moded, status = estatus, adviser = estatus2 WHERE idnum == idpointer
CASE this.parent.CboStatus2.value = "Part Time"
UPDATE tsulat SET grade = "P", mode = moded, status = estatus, adviser = estatus2 WHERE idnum == idpointer
CASE this.parent.CboStatus2.value = "Utility"
UPDATE tsulat SET grade = "U", mode = moded, status = estatus, adviser = estatus2 WHERE idnum == idpointer
ENDCASE
ELSE
UPDATE tsulat SET grade = graded, mode = moded, adviser = advyser WHERE idnum == idpointer
ENDIF


IF ALLTRIM(idpointer) <> ALLTRIM(idnamber)

Q = ALLTRIM(idpointer)
R = ALLTRIM(idnamber)

REPLACE tsulat.idnum WITH ALLTRIM(R)

UNLOCK IN TSULAT

SELECT trans

GO top

IF FLOCK()

IF UPPER(q) = "CANCELED" OR UPPER(R) = "CANCELED"
RETURN
ENDIF

Update trans set idnum=ALLTRIM(R) Where ALLTRIM(Q)=ALLTRIM(idnum)
CTR =_TALLY
ELSE
WAIT WINDOW 'Unable to open TRANSACTION Table; try again later!' NOWAIT
ENDIF

MESSAGEBOX("There are " + ALLTRIM(STR(CTR)) + " records updated in TRANSACTIONS DATABASE!",0,"Transactions")
UNLOCK IN TRANS

IF FLOCK()

SELECT PADR(ALLTRIM(UPPER(sname)) + ", " + ALLTRIM(fname),25), idnum FROM tsulat ORDER BY sname, fname INTO CURSOR csrdemo READWRITE

ENDIF​
 
Where exactly are you seeing this copy of the record? The only place in your code where you are actually creating records (as opposed to updating existing records) is in the SELECT statement at the end. Are the copies that you are creating in the csrDemo cursor?

As far as I can see, that cursor will always contain all the records from Tsulat. Is that what you want?

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Yes mike… you are correct… the cursor Csrdemo is written at init procedure the used in every page,
 
Mandy,

that's not answering what Mike asked.

This code is not causing a record to duplicate. His remark that the SELECT is the only place where records are created is correct, it won't create records in TSULAT.DBF, though. It just copies all records sname/fname in a specific name format to crsDemo.

You might have some double names in there, but not only after you edited data, if two records are about the same person, then crsDemo will already have this name twice to start with. You're not limiting crsDemo in any way to only have distinct names. And as you select an idnum that's differing per record, you also might not want to get distinct names, as that would remove idnums from the cursor.

All I can say for sure is that this code does not double records in tsulat. Records are added with append, with insert and if you append or insert records into the tablebuffer of a dbf or a view, TABLEUPDATE() finally actually adds them to the DBF. Only such code can cause double records. And the way it happens can be tricky. You might copy a record and APPEND the copy, where you should instead UPDATE the original.

Chriss
 
Just a side remark:
I your code

Code:
SELECT trans

GO top

IF FLOCK()

IF UPPER(q) = "CANCELED" OR UPPER(R) = "CANCELED"
RETURN
ENDIF

you forgot to UNLOCK before RETURN.

HTH.

P.S. I once took over a program from retired employee, and was given a list of discrepancies. One of them was that the program reported that there were zero funds, while the account manager knew that the money was there. She had to exit the program and relaunch it to see these money. I found that my predecessor SET FILTER ON in several of the account-related procedures ... and forgot to SET FILTER OFF... Thus when she switched from that account to another, and the funds table still had this filter set to the previous account's ID... you've got the picture.

Regards,

Ilya
 
Mandy, my name is ILYA (I'm not "shouting").
None taken! :)

Mike, you are right, mea culpa! [sad]
Last time I worked with VFP was May 2019... "You don't use it - you lose it", as saying goes.

Regards,

Ilya
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top