Solved

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

Posted on 2013-01-02
7
378 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to not remove leading zeros 9 38
Is it possible to reset DSum? 12 41
format date field on certain entries 8 28
How autonumber field on a form 16 6
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

911 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

23 Experts available now in Live!

Get 1:1 Help Now