Solved

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

Posted on 2013-01-02
7
369 Views
Last Modified: 2013-01-07
Need vba code to copy and replace data in a table called Table1 to a table called Table2 within the same database. Thank you
0
Comment
Question by:Startrac98
7 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 38738016
>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
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38738056
<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
 
LVL 30

Expert Comment

by:hnasr
ID: 38738086
If you mean copy:

 DoCmd.CopyObject , "Table2", acTable, "Table1"
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 26

Expert Comment

by:jerryb30
ID: 38738155
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
 
LVL 30

Expert Comment

by:hnasr
ID: 38738341
Agree with  boag2000, "Copy and Replace" , I overlooked  this requirement.

A sample database with required output clarifies the issue.
0
 

Author Closing Comment

by:Startrac98
ID: 38750778
was exactly what I needed.  Simply.  Thanks.
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 38750792
Thanks for the grade.  Good luck with your project.  -Jim
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now