Append "current record" query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to be able to copy my current record and then paste most of it as a
new record,

I don't want to duplicate all fields, I just want to duplicate some fields
and put different data in some fields (like in the date column I want to put
the Date () function)

Basically I want to make an append query based on my current record
 
Try this

Docmd.RunSql "INSERT INTO TableName( Field1,Field2,Field3) VALUES ('" &
me.Field1String & "'," & Me.Field2Number & ", #" & Me.Field3Date & "#)"

For string field you need single quote before and after
For Date field you need # before and after
For Number field you don't need anything
 
Your form has a RecordsetClone property which lets you get at another record
than the one you are seeing in the form.

This example assumes you have a command button named cmdDupe on your form.
When you click the button it moves the form's RecordsetClone to the current
record, moves the form to the new record, and copies in the fields you want
to duplicate. You can assign other values as well, or leave them for the
user to finish filling in.

Private Sub cmdDupe_Click()
Dim rs As DAO.RecordsetClone
If Me.Dirty Then Me.Dirty = False 'Save first.
If Me.NewRecord Then
MsgBox "Pick a record to duplicate."
Else
'Select the current record in the clone set.
Set rs = Me.RecordsetClone
rs.Bookmark = Me.Bookmark

'Move the form to a new record.
RunCommand acCmdRecordsGotoNew

'Copy the old fields into the form.
Me.Surname = rs!Surname
Me.City = rs!City
'etc for your other fields.
End If
Set rs = Nothing
End Sub
 

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

Back
Top