?
Solved

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

Posted on 2013-01-02
7
Medium Priority
?
415 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 66

Accepted Solution

by:
Jim Horn earned 2000 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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 66

Expert Comment

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

Featured Post

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

801 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