Copy Record

Joshann

Registered User.
Local time
Today, 07:22
Joined
Mar 22, 2002
Messages
142
Is there a way (with code) to "copy" a row of a recordset and then "paste" it as a new record in the recordset?

For example, you could do the following:
Dim rst as new ADODB.Recordset
Dim cn as ADODB.Connection

Set cn as CurrentProject.Connection

rst.Open "Address", cn, adOpenKeyset, adLockOptimistic

'Save the value of each field to a different variable
strField1 = rst!Field1
strField2 = rst!Field2
.
.

rst.AddNew
rst!Field1 = strField1
rst!Field2 = strField2
.
.
rst.Update

The problem is that if you have a bunch of fields, it is a pain to type them all like that. Is there some way to just get the values of all the fields at once and then store them all at once into a new record?
 
Use the QBE Grid and create an Insert SQL vice opening a recordset. (You will save processing/memory)

Code:
stSQL="INSERT INTO [Table] ( [Field1], [Field2], [Field3, etc... )
SELECT [Field1], [Field2], [Field3], etc...
FROM [Table]
WHERE ((([Table].[UniqueID])=" & [UniqueId of Record to be copied] & "));"


Currentdb.Execute stSQL
 
Last edited:
Thanks!
 

Users who are viewing this thread

Back
Top Bottom