Copying Records

G

Guest

Is there a quick way to move to a record in a recordset, copy the record, open a new recordset, then paste the copied record
I have numerous fields in the recorset and would like to save some typing. Do I have to go through this sort of thing
Field1 = rst1!Field
Field2 = rst1!Field2 'et
rst2!Field1 = Field
rst2!Field2 = Field2 'et
Both recordsets will have identical layout
Expanding a bit. When a delete record button is clicked on MyForm, I would like the deleted record to be written to a deleted records table
Thanx
 
N

Nikos Yannacopoulos

You can do the field by field "copying" without much typing of code, just
use a simple loop:

'find record in rst1
rst2.AddNew
For i = 0 to rst1.Fields.Count - 1
rst2.Fields(i) = rst1.Fields(1)
Next
rst2.Update

the same can be applied in copying your record to the deleted records table
before deleting it. Alternatively, you could use an SQL append query,
something along the lines of:
strSQL = "INSERT INTO [TargetTableName] ( Field1, Filed2... )"
strSQL = strSQL & " SELECT SourceTable.Field1, SourceTable.Field2..."
strSQL = strSQL & " FROM SourceTableName"
strSQL = strSQL & " WHERE SourceTableName.PKField = ' " & currentrecordPK &
" ' "
'(drop the single quotes above for numneric PK)
DoCmd.RunSQL

HTH,
Nikos

prokofiev said:
Is there a quick way to move to a record in a recordset, copy the record,
open a new recordset, then paste the copied record.
I have numerous fields in the recorset and would like to save some typing.
Do I have to go through this sort of thing:
Field1 = rst1!Field1
Field2 = rst1!Field2 'etc
rst2!Field1 = Field1
rst2!Field2 = Field2 'etc
Both recordsets will have identical layout.
Expanding a bit. When a delete record button is clicked on MyForm, I would
like the deleted record to be written to a deleted records table.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top