Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2013
    Posts
    14

    Combining Multiple Tables

    I have 24 tables with identical fields that I want to combine into one table. If I were doing it table by table, I would use the ISERT Statement below. What would the language be to combine multiple tables like tblBHCareLog into tblCombinedLog9_24_15?

    INSERT INTO tblCombinedLog9_24_15( Lname, Fname, MedicaidID )
    SELECT tblBHCareLog.LName, tblBHCareLog.FName, tblBHCareLog.BestGuestMedicaidID


    FROM tblBHCareLog;

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    you really should stop using table names with dates. (the date goes in a table field, not the table name)
    But
    INSERT INTO tblCombinedLog9_24_15 ( Lname, Fname, MedicaidID )
    SELECT LName, FName, BestGuestMedicaidID
    FROM tblBHCareLog;

  3. #3
    Join Date
    Aug 2013
    Posts
    14
    Thanks for getting back so fast and that is good feedback on table names. That language will allow me to add one table to the master table at a time. I am looking for a query that will add many tables together into the master at once.

  4. #4
    JamesDeckert is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jul 2015
    Location
    Salina, KS
    Posts
    262
    you'll need to code it in vba to build the query as ranman shows, but replacing the part of the query that you need to change. Maybe put an array with the 24 variable parts and then loop through the array building the sql string using the array?

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Why do you have 24 tables with identical structure?

    Build a UNION query to combine the tables in a single dataset. This will essentially create the single table should have been to begin with.

    SELECT LName, FName, BestGuestMedicaidID, "BHCare" AS Source, #9/24/2015# AS LogDate FROM tblBHCareLog
    UN ION SELECT LName, FName, BestGuestMedicaidID, "something", #9/24/2015# FROM tblsomething
    ...;

    Now use that query as source for the INSERT SELECT action.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 14
    Last Post: 07-22-2013, 12:39 PM
  2. Replies: 1
    Last Post: 10-21-2012, 11:31 PM
  3. combining multiple tables in to one master
    By joebox8 in forum Queries
    Replies: 5
    Last Post: 06-23-2011, 06:18 AM
  4. Combining multiple tables
    By Duncan in forum Access
    Replies: 1
    Last Post: 03-27-2011, 08:41 AM
  5. Replies: 1
    Last Post: 06-21-2007, 01:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums