How to Copy a General Field from One Record to Another

ID: Q113443

2.50 2.50a 2.50b WINDOWS kbole

The information in this article applies to:

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 KBSubcategory: FxinteropOle
Keywords          : kbcode FxinteropOle 
Version           : 2.50 2.50a 2.50b
Platform          : WINDOWS

Last Reviewed: May 22, 1998