We help IT Professionals succeed at work.

Copy records with Macro to other fields

Gilberto Sanches
Gilberto Sanches asked
on
Hi Expert,

In Access 2016, how can we copy records from one field to another in the same table, with a macro?
Comment
Watch Question

Software Team Lead
Commented:
how can we copy records from one field to another in the same table, with a macro?

in general, try use an Update query, such as:

Update yourTable set yourField = anotherField Where yourCondition = true

Open in new window


to execute it in Macro, try like:
yourSQL = Update yourTable set yourField = anotherField Where yourCondition = true
CurrentDb.Execute yourSQL

Open in new window


or
yourSQL = Update yourTable set yourField = anotherField Where yourCondition = true
DoCmd.RunSQL yourSQL

Open in new window

Scott McDaniel (EE MVE )Infotrakker Software
Most Valuable Expert 2012
Top Expert 2014

Commented:

When/How would you do this? When the user clicks a button, or when some event occurs?


In general, it's a bad idea to duplicate data like this, unless you're copying over a record to set "default" values - that is, you will "duplicate" the data, but you're going to update one or more fields after you duplicate.

Most Valuable Expert 2015
Distinguished Expert 2018

Commented:

Yes. Study my simple and fast code in this old question: Clone Record

Gilberto SanchesFreelance ICT Consultant

Author

Commented:
Copying should happen when the user clicks on a button.

A update query made it possible. It works.

Thanks Ryan