Importing Excel flat file to Access tables

Anonymous
2022-03-22T19:13:47+00:00

I have an Excel file with rows of data. Each row contains order information. I want to import the excel file into Access and parse out all of the related data(columns) to their applicable normalized tables. For instance, an Order contains Material. I want to import the "OrderNum" field to "tblOrdersMain" and the "MaterialNumber" field to "tblMaterials". Attached is my table structure. The highlighted fields are in the Excel file. I'm trying to import the xlsx file and populate the correct tables. Can this be done only with extensive code?

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

10 answers

Sort by: Most helpful
  1. Anonymous
    2022-03-22T22:45:28+00:00

    GroverParkGeorge...thank you. I will try that as soon as I have the opportunity. I think I need to perform multiple verifications on the excel data prior to adding to the database. The excel file, I am told, as I get that from an outside source, will have new records as well as changed records. But that poses another level of complexity.

    0 comments No comments
  2. ScottGem 68,780 Reputation points Volunteer Moderator
    2022-03-23T12:01:00+00:00

    There is no need to import the Excel file. Instead, I would simply link to it.

    One of the main questions I would have is whether the Excel sheet includes the MaterialID or the MaterialDesc. Another question is whether it includes the CustomerID or the CustName.

    I would do this in a VBA module Where I would test the data in the linked Excel table against what's in Access tables before updating your tables.

    0 comments No comments
  3. Anonymous
    2022-03-24T00:47:04+00:00

    Scottgem...thank you for the advice. I am going to try the linking to test the data. As far as the excel sheet, the Material, ie product number, is in the excel sheet. NOT the material ID. The material number is unique within the parent table of Materials, but the spreadsheet will have this number on many rows. This is the same for Customer. The Excel sheet holds the Customer Number, which again is unique in the parent table but will appear on many rows of the spreadsheet.

    If all data is valid and the parent tables contain the data in the excel sheet, can append queries populate all of the tables? I am having difficulty writing the queries as I get key violation errors.

    As soon as I am able to, I will try again and post the sql statement that I have. I am starting with updating the one-side of the relationships first.

    0 comments No comments
  4. ScottGem 68,780 Reputation points Volunteer Moderator
    2022-03-24T01:44:10+00:00

    Ok, It is possible to write a query that cany update Existing records and Append new ones. But I keep forgetting the syntax. So you can use 2 queries:

    I would do the Append first

    INSERT INTO table (field list)

    SELECT field list FROM [linked Excel Sheet];

    Then the Update

    UPDATE table SET fieldname = Excel.fieldname

    WHERE CustNumber = excel.custnumber;

    You can do the same thing with the MaterialNumber.

    0 comments No comments
  5. DBG 11,531 Reputation points Volunteer Moderator
    2022-03-24T02:09:17+00:00
    0 comments No comments