Results 1 to 7 of 7
  1. #1
    Marcia's Avatar
    Marcia is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Aug 2019
    Posts
    37

    Extracting data from multiple tables into a separate table and to consolidate multiple tables

    Hi all. I have seven tables imported from Excel with the same field names. The field names (12 of them) include Name and Mailing Address. I would like to create a Name table, extracting all the distinct names with their corresponding address from the 7 tables. A name that appear in different address should be included in the new table. I tried the "Append" but it only returned those names and addresses with matching records in all tables. How do I include the distinct names and addresses? also, how do I consolidate the 7 tables into one big table? thank you.

  2. #2
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Well, "Name" is a reserved word (it is a property) and shouldn't be used as an object name.


    You want to merge 7 tables that have identical field names?
    Is this a one time thing?


    For a one off job, I would use 7 append tables.

    What is the table structure (field names)?

  3. #3
    Marcia's Avatar
    Marcia is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Aug 2019
    Posts
    37
    Well, "Name" is a reserved word (it is a property) and shouldn't be used as an object name.
    I'm sorry, the actual field name is "NameOfOwner"
    You want to merge 7 tables that have identical field names?
    Yes i would like to merge the 7 tables
    Is this a one time thing?
    It is not a one time thing because the source tables might be edited later on
    For a one off job, I would use 7 append tables.
    I tried the ff but it returned an error message of Syntax error in query, incomplete query clause
    SELECT * Into MainTable From 2006Table
    UNION ALL
    SELECT * Into MainTable From 2014Table
    UNION ALL
    What is the table structure (field names)?
    Here they are:
    RowNo - Autonumber
    TaxDecNo - Text
    NameOfOwner - Text
    Administrator - Text
    MailingAddress - Text
    Location - Text
    Barangay - Text
    Classification - text
    PreviousNo - Text
    Area - Number
    MVLand - Number
    MVImp - Number
    MVMach - Number
    AVLand - Number
    AVImp - Number
    AVMach - Number
    YearBegins - Number
    Remarks - Text
    Last edited by Marcia; 08-29-2019 at 09:32 PM.

  4. #4
    Join Date
    Apr 2017
    Posts
    1,680
    1. Link all 7 Excel tables into Access database;

    2. Create an Access table with structure identical with linked Excel tables (with atonumber field as PK);

    3. Create a procedure which runs 7 INSERT INTO queries like
    Code:
    INSERT INTO YourAccessTable (TaxDecNo,  ..., Remarks)
    SELECT exc.TaxDecNo, ..., exc.Remarks
    FROM YourExcelTable1 exc LEFT JOIN YourAccessTable acc  acc.NameOfOwner = exc.NameOfOwner AND acc.MailingAddress = acc.MailingAddress
    WHERE acc.NameOfOwner Is Null AND exc.NameOfOwner Is Not Null
    3. Set up some event which runs the procedure and updates your Access table with new mailing info from linked Excel tables. When you also want to update changes made to old info, you need 7 UPDATE and 7 DELETE queries too.

  5. #5
    Marcia's Avatar
    Marcia is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Aug 2019
    Posts
    37
    Big thanks for this Arvi. I will get try this once I have organized the 7 excel tables for merging.

  6. #6
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Arvil has provided you with a solution. I just want to make a few comments about the code you tried.




    You tried
    Quote Originally Posted by Marcia View Post
    SELECT * Into MainTable From 2006Table
    UNION ALL
    SELECT * Into MainTable From 2014Table
    UNION ALL
    This won't execute for a couple of reasons.
    1) You used a wildcard to select the fields. But one of the fields "RowNo", which is an Autonumber type field. You DON'T want to and can't append the autonumbers from the 7 tables. An Autonumber field is a unique field - and I would bet there are duplicate numbers in that field. Do you think that a "RowNo" would be 1 in each of the tables?

    2) The syntax you used is "SELECT * Into MainTable...". "Select Into" creates a new table. So, if you had 7 statements like this, you would be trying to create 7 tables named "MainTable". Since each table name MUST be unique....... Boom! It fails!


    You could create a union query that merges the data from 7 tables into one query: ( does not eliminate duplicates)
    Code:
    SELECT xlsTable.TaxDecNo,  xlsTable.NameOfOwner,  xlsTable.Administrator,  xlsTable.MailingAddress,  xlsTable.Location,  xlsTable.Barangay,  xlsTable.Classification,  xlsTable.PreviousNo,  
    xlsTable.Area,  xlsTable.MVLand,  xlsTable.MVImp,  xlsTable.MVMach,  xlsTable.AVLand,  xlsTable.AVImp,  xlsTable.AVMach,  xlsTable.YearBegins,  xlsTable.Remarks FROM 2006Table AS xlsTable
    UNION ALL
    SELECT xlsTable.TaxDecNo,  xlsTable.NameOfOwner,  xlsTable.Administrator,  xlsTable.MailingAddress,  xlsTable.Location,  xlsTable.Barangay,  xlsTable.Classification,  xlsTable.PreviousNo,  
    xlsTable.Area,  xlsTable.MVLand,  xlsTable.MVImp,  xlsTable.MVMach,  xlsTable.AVLand,  xlsTable.AVImp,  xlsTable.AVMach,  xlsTable.YearBegins,  xlsTable.Remarks FROM 2007Table As xlsTable
    UNION ALL
    SELECT xlsTable.TaxDecNo,  xlsTable.NameOfOwner,  xlsTable.Administrator,  xlsTable.MailingAddress,  xlsTable.Location,  xlsTable.Barangay,  xlsTable.Classification,  xlsTable.PreviousNo,  
    xlsTable.Area,  xlsTable.MVLand,  xlsTable.MVImp,  xlsTable.MVMach,  xlsTable.AVLand,  xlsTable.AVImp,  xlsTable.AVMach,  xlsTable.YearBegins,  xlsTable.Remarks FROM 2008Table AS xlsTable
    .
    .
    .
    Note that this union query uses an alias (xlsTable) in the FROM clause.

    This query could be a saved query or in code.


    Then you could have (MainTable must already exist):
    Code:
    INSERT INTO MainTable (TaxDecNo, NameOfOwner, Administrator, MailingAddress, Location, Barangay, Classification, PreviousNo, Area, MVLand, MVImp, MVMach, AVLand, AVImp, AVMach, YearBegins, Remarks )
    SELECT xlsTable.TaxDecNo,  xlsTable.NameOfOwner,  xlsTable.Administrator,  xlsTable.MailingAddress,  xlsTable.Location,  xlsTable.Barangay,  xlsTable.Classification,  xlsTable.PreviousNo,  xlsTable.Area,  
    xlsTable.MVLand,  xlsTable.MVImp,  xlsTable.MVMach,  xlsTable.AVLand,  xlsTable.AVImp,  xlsTable.AVMach,  xlsTable.YearBegins,  xlsTable.Remarks FROM 2006Table xlsTable
    UNION ALL
    SELECT xlsTable.TaxDecNo,  xlsTable.NameOfOwner,  xlsTable.Administrator,  xlsTable.MailingAddress,  xlsTable.Location,  xlsTable.Barangay,  xlsTable.Classification,  xlsTable.PreviousNo,  xlsTable.Area, 
     xlsTable.MVLand,  xlsTable.MVImp,  xlsTable.MVMach,  xlsTable.AVLand,  xlsTable.AVImp,  xlsTable.AVMach,  xlsTable.YearBegins,  xlsTable.Remarks FROM 2007Table xlsTable
    UNION ALL
    SELECT xlsTable.TaxDecNo,  xlsTable.NameOfOwner,   xlsTable.Administrator,  xlsTable.MailingAddress,  xlsTable.Location,   xlsTable.Barangay,  xlsTable.Classification,  xlsTable.PreviousNo,   xlsTable.Area,  
    xlsTable.MVLand,  xlsTable.MVImp,  xlsTable.MVMach,   xlsTable.AVLand,  xlsTable.AVImp,  xlsTable.AVMach,   xlsTable.YearBegins,  xlsTable.Remarks FROM 2008Table xlsTable
    .
    .
    .
    Note: Arvil's query handles duplicates - the method above does not. You would have to run more code to eliminate duplicates.

  7. #7
    Marcia's Avatar
    Marcia is offline Advanced Beginner
    Windows 7 64bit Access 2013 64bit
    Join Date
    Aug 2019
    Posts
    37
    Thank you again Steve for going the extra mile in expounding on the method of merging tables. I will try these for when the seven tables shall have been substantially cleaned of errors by the encoder. We find it easier to edit the data in Excel table than in Access.

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

Similar Threads

  1. Replies: 2
    Last Post: 09-20-2017, 01:21 PM
  2. Extracting data in a subform to a table
    By Kichen in forum Forms
    Replies: 3
    Last Post: 04-06-2016, 02:30 AM
  3. Replies: 1
    Last Post: 11-12-2012, 02:48 PM
  4. Help! Extracting Data from table to Form.
    By iProRyan in forum Forms
    Replies: 3
    Last Post: 01-29-2012, 02:12 PM
  5. Replies: 7
    Last Post: 06-16-2010, 09:19 AM

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