How to Copy a General Field from One Record to Another

Last reviewed: April 30, 1996
Article ID: Q113443
The information in this article applies to:
  • Microsoft FoxPro for Windows, versions 2.5, 2.5a, and 2.5b

SUMMARY

You can copy a general field from one record to another by using the KEYBOARD command and the copy key combination (CTRL+C) to place the OLE object on the Windows Clipboard. You can then use the paste key combination (CTRL+V) to insert the OLE object in the general field of the target record. For more information about this process, see below.

MORE INFORMATION

Go to the record containing the general field you want to copy. Use the KEYBOARD command to issue CTRL+C and CTRL+W. Open a window for the process to take place.

Go to the record containing the general field you want to contain the OLE object you now have on the Clipboard. Use the KEYBOARD command to issue CTRL+V and CTRL+W. Open a window for the process to take place.

Sample Code

To test the sample code below, you can use the OLETABLE.DBF file in the FOXPROW\SAMPLE\OLE subdirectory. This table contains a general field called OBJECT.

The following code example works on a copy of the database you select. You will have to make the appropriate changes to this code in order to have it work on a live table. Two files are created during the execution of this code (OLETEST.DBF and OLETEST.FPT); you can delete these files when you are finished.

   CLOSE DATABASES
   *COPY and USE the database.
   testfile= GETFILE('dbf','Select the OLE table')
   IF FILE('oletest.dbf')
      ERASE oletest.dbf
      ERASE oletest.fpt
   ENDIF
   IF !EMPTY(testfile)
      COPY FILE (testfile) TO oletest.dbf
      COPY FILE LEFT(testfile,LEN(testfile)-3)+"FPT" TO oletest.fpt
      USE oletest

   ELSE
      WAIT WINDOW TIMEOUT 1.5  'No table selected...'
      RETURN
   ENDIF

   *Set record pointer to source record
   BROWSE TITLE 'Select source record by moving to it... '+;
      'Press <ESC> to select record'
   fieldname='OLETEST.OBJECT'

   DEFINE WINDOW updt_ole AT 5,15 SIZE 2,90 FONT "FoxPrint" TITLE ;
      "Copying general field &fieldname from record "+LTRIM(STR(RECNO()))
   ACTIVATE WINDOW updt_ole

   KEYBOARD '{Ctrl+C}'
   KEYBOARD '{Ctrl+W}'
   MODIFY GENERAL (fieldname) IN WINDOW updt_ole

   RELEASE WINDOW updt_ole

   *Set record pointer to destination record
   BROWSE TITLE  'Select destination record... Press <ESC> to select it'
   fieldname='OLETEST.OBJECT'

   DEFINE WINDOW copymsg AT 5,15 SIZE 2,90 FONT "FoxPrint" TITLE ;
      "Pasting to &fieldname in record "+LTRIM(STR(RECNO()))
   ACTIVATE WINDOW copymsg

   KEYBOARD '{Ctrl+V}'
   KEYBOARD '{Ctrl+W}'
   MODIFY GENERAL (fieldname) IN copymsg

   RELEASE WINDOW copymsg
   WAIT WINDOW NOWAIT "Done!"


Additional reference words: FoxWin 2.50 2.50a 2.50b
KBCategory: kbole kbprg kbcode
KBSubcategory: FxinteropOle


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 30, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.