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!

VFP 6 Duplicating a record 2

Status
Not open for further replies.

eric43

Programmer
Apr 29, 2005
94
AU
I have a need to take all the fields in a in a record and make a duplicate record with the only difference being a ref number in one of the fields.

Is there a way to do this without copying all field values into an array or variable. I have a number of tables that I need to do this with.

Can I use a len type statement to control a FOR - NEXT loop running through all the fields?

Thanks

Eric
 
I think SCATTER NAME can be usefull command.

LOCAL loRecord
SELECT Alias
SCATTER NAME loRecord
loRecord.FieldName1 = NewValueForFieldName1
INSERT INTO Alias FROM NAME loRecord

If INSERT INTO FROM NAME isn't supported in your/older version of VFP, you can use APPEND BLANK + GATHER NAME loRecord.
Or you can use a SCATTER/GATHER/INSERT syntax version with array instead of object.
 
Interestingly ( and frustratingly) this code does not 'copy' a memo field at all.

I guess these have to be copied individually after all - however the above code has saved a lot of work so far!

Thanks guys

Eric
 
You can use

SCATTER TO mycopy MEMO
then
APPEND BLANK
GATHER FROM mycopy MEMO
then REPLACE ... fields you want to change

OR

SCATTER TO mycopy field1, field2... MEMO
APPEND BLANK
GATHER FROM mycopy field1, field2... MEMO

Kaz
 
SORRY.. forgot to include "FIELDS" - You can use

SCATTER TO mycopy MEMO
then
APPEND BLANK
GATHER FROM mycopy MEMO
then REPLACE ... fields you want to change

OR

SCATTER TO mycopy FIELDS field1, field2... MEMO
APPEND BLANK
GATHER FROM mycopy FIELDS field1, field2... MEMO

Kaz
 
If you want to do it in a browse window, take a shot at SET CARRY ON: If that is on CTRL+Y (or CTRL+T) will add a new record and carries the content of the last record over to the new one. Now You'd only need to modify that one field.

Bye, Olaf.
 
Thanks everybody - very helpful

Eric
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top