vba code to copy a table to another table in same DB

Need vba code to copy and replace data in a table called Table1 to a table called Table2 within the same database. Thank you
Startrac98Asked:
Who is Participating?
 
Jim HornConnect With a Mentor Microsoft SQL Server Developer, Architect, and AuthorCommented:
>Need vba code to copy and replace data
Assuming this means replace all of Table1 records with Table2 records, that's Two queries:

DELETE * FROM Table1

INSERT INTO Table1 SELECT * FROM Table2

This assumes that the design of Table1 and Table2 are an exact match.
0
 
Jeffrey CoachmanMIS LiasonCommented:
<Need vba code to copy and replace data in a table called Table1 to a table called Table2 within the same database.>

Not sure I understand here...?

What does "Copy and replace" mean? ...and how would you both Copy and Replace to another table?

Is your goal here simply to append data from one table to another?

If so then you must provide an example of both tables, (a small sample DB file would be best)  ...then post a clear graphical example of the *exact* result you need.
0
 
hnasrCommented:
If you mean copy:

 DoCmd.CopyObject , "Table2", acTable, "Table1"
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
jerryb30Commented:
Are you wanted to update existing records in table2 with data in table1?

Update table1, table2 set table2.somefield = table1.somefield where table1.IDfield = tabl2.idField
0
 
hnasrCommented:
Agree with  boag2000, "Copy and Replace" , I overlooked  this requirement.

A sample database with required output clarifies the issue.
0
 
Startrac98Author Commented:
was exactly what I needed.  Simply.  Thanks.
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks for the grade.  Good luck with your project.  -Jim
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.