Microsoft KB Archive/177304

= How To Programmatically Copy the Current Record to a New Record =

Article ID: 177304

Article Last Modified on 7/1/2004

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 3.0b Standard Edition
 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 5.0a
 * Microsoft Visual FoxPro 6.0 Professional Edition
 * Microsoft Visual FoxPro 3.0 for Macintosh
 * Microsoft FoxPro 2.5b
 * Microsoft FoxPro 2.5a
 * Microsoft FoxPro 2.5b
 * Microsoft FoxPro 2.6 Standard Edition
 * Microsoft FoxPro 2.6a Standard Edition
 * Microsoft FoxPro 2.6a Professional Edition for Macintosh
 * Microsoft FoxPro 2.0
 * Microsoft FoxPro 2.5b for MS-DOS
 * Microsoft FoxPro 2.5a
 * Microsoft FoxPro 2.5b for MS-DOS
 * Microsoft FoxPro 2.6 for MS-DOS
 * Microsoft FoxPro 2.6a Standard Edition
 * Microsoft FoxPro 2.6 for SCO/UNIX

-



This article was previously published under Q177304



SUMMARY
This article illustrates how to programmatically copy the contents of a selected record into a new record in the same table.



MORE INFORMATION
The following code may be used in either a program (.prg) file or interactively in the FoxPro Command window.

NOTE: The code in Step 1 creates a new table used to provide sample data for the rest of the steps that illustrate how to copy an existing record. However, any table may be used provided that a duplicate record may be added and no index primary key is violated. Primary key indexes are only available in versions of Visual FoxPro.

  Copy the following code to a test program and run it to create Testcopy.dbf that contains five sample records: ***** Table setup for TEST of record copy ***** CREATE TABLE 'testcopy.dbf' ; (FNAME C(12), LNAME C(10), SEQUENCE I(2))

***** Add five records for testing ***** INSERT INTO testcopy (FNAME, LNAME, SEQUENCE) ; VALUES ('Rutherford B.', 'Hayes', 19) INSERT INTO testcopy (FNAME, LNAME, SEQUENCE) ; VALUES ('James A.', 'Garfield', 20) INSERT INTO testcopy (FNAME, LNAME, SEQUENCE) ; VALUES ('Chester A.', 'Arthur', 21) INSERT INTO testcopy (FNAME, LNAME, SEQUENCE) ; VALUES ('Grover', 'Cleveland', 22) INSERT INTO testcopy (FNAME, LNAME, SEQUENCE) ; VALUES ('Benjamin', 'Harrison', 23)   This step shows one way that may be used to locate the record to copy. LOCATE FOR sequence = 22   The following code copies and creates a duplicate record.

NOTE: The MEMO clause used below is needed only if there is a memo field. The contents of a General field will not be copied. SCATTER MEMVAR MEMO  && Copies contents of current record to memory. APPEND BLANK         && Creates a new blank record. GATHER MEMVAR MEMO   && Copies contents from memory to new record.  BROWSE the table to view the records. Note that record number 6 is a duplicate of record number 4.

