Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy current record on form to new record in underlying table

Status
Not open for further replies.

Moss100

Technical User
Aug 10, 2004
579
0
16
GB
Hello,

I have a single form which does not allow addition of records.

I would like a button on the form to copy the current record and duplicate it so that it is stored in the underlying table.

Please could someone give me some basic code for doing this.

Many thanks Mark

 
Set the code behind the button to run an SQL statement like:


Code:
Dim strSQL as String
strSQL = "INSERT INTO tblYourTable ([Your field list here]) " & _
    "SELECT [Your field list here] FROM tblYourTable WHERE [YourPrimaryKey] = " & Me.txtYourPrimaryKey
CurrentDb.Execute strSQL, dbFailOnError

If you need more help, we need actual table and field names and data types.

Duane
Hook'D on Access
MS Access MVP
 
Is there a way of selecting all fields or do I have to put each field in separately?

If I select * - would that work, or would it error as it would duplicate the primary key?

Many thanks for your help this far.

Mark
 
You may try it, but it will error (just a guess here) because of PK
So list all the fields (without PK field) twice in your (dhookom's) INSERT statement.

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top