Solved

How to combine multiple tables in Access 2010 into single table

Posted on 2014-09-03
7
7,038 Views
Last Modified: 2014-09-12
Hello,

I have 7 tables of information, all tables have the same fields.  I would like to combine the tables into 1 master table and then remove the previous ones.  My intent to do this is so I then have just one table to work with in trying to isolate and remove duplication.  Any and all assistance would be greatly appreciated.
0
Comment
Question by:FreddyBass
7 Comments
 
LVL 37

Expert Comment

by:Neil Russell
ID: 40301936
INSERT INTO maintablename SELECT * FROM firstoldtable
INSERT INTO maintablename SELECT * FROM secondoldtable
INSERT INTO maintablename SELECT * FROM nextoldtable

etc...
0
 

Author Comment

by:FreddyBass
ID: 40301982
Hi Neilsr,

Thank you for your input, where to put what you have written?

INSERT INTO maintablename SELECT * FROM firstoldtable
INSERT INTO maintablename SELECT * FROM secondoldtable
INSERT INTO maintablename SELECT * FROM nextoldtable
0
 
LVL 37

Accepted Solution

by:
Neil Russell earned 500 total points
ID: 40301990
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 30

Expert Comment

by:hnasr
ID: 40302004
Try:

SELECT * INTO mainTable
FROM (SELECT * FROM tbl1 UNION  SELECT * FROM tbl2 ...  UNION SELECT * FROM tbl7)

... to be replaced by UNION for all other remaining tables
0
 

Author Comment

by:FreddyBass
ID: 40302013
Hello Neilsr,

I will have a look at the following link and let you know if that provides the solution I am looking for.

Thank you

Fred
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 40303643
It might be better to do this operation in VBA code.  If each table has an ID field as the key field, you won't be able to append to that field.  Also, you may need to check for duplicates before adding a record.  In some cases it might be more appropriate to update an existing record rather than adding a new one.  here is some typical code for an "append or update" choice:
      strSearch = "[Code] = " & lngCode
      Debug.Print "Search string: " & strSearch
      rstTarget.FindFirst strSearch
      
      If rstTarget.NoMatch = True Then
         'Add new record
         rstTarget.AddNew
         rstTarget![Code] = lngCode
         rstTarget![TechName] = strTech
         rstTarget![WorkDate] = dteWork
         rstTarget![StartTime1] = rstSource![StartTime]
         rstTarget![EndTime1] = rstSource![EndTime]
         curRate = CCur(Nz(rstSource![Rate]))
         rstTarget![Rate] = curRate
         rstTarget.Update
      Else
         'Update existing record
         rstTarget.Edit
         rstTarget![StartTime2] = rstSource![StartTime]
         rstTarget![EndTime2] = rstSource![EndTime]
         rstTarget.Update
      End If

Open in new window

0
 

Author Closing Comment

by:FreddyBass
ID: 40319945
Thank you for providing me the link, I was able to find more information there for what I am trying to do
0

Featured Post

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)

Join & Write a Comment

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
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…

758 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