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. DBG 11,531 Reputation points Volunteer Moderator
    2022-03-22T19:20:26+00:00

    One approach is to import the Excel file into a temporary table and then use a series of APPEND queries to normalize the data into the appropriate tables in Access.

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2022-03-22T19:29:33+00:00

    Thank you theDBguy. That's exactly what I'm trying to do but I have no clue how to use append queries to populate all of the appropriate tables. However, the data in the child tables, ie the Materials table, shouldn't be appended because the material item will already exist in the Materials table.

    0 comments No comments
  3. DBG 11,531 Reputation points Volunteer Moderator
    2022-03-22T22:10:23+00:00

    You could start slow. Import the Excel file into a temporary table first. Then, create an APPEND query to do the first child table. Save that query, so you can use it later. Continue to create all the queries you need to transfer all the data. Once you have all your queries, you can execute them in sequence the next time you need to import your data again.

    2 people found this answer helpful.
    0 comments No comments
  4. George Hepworth 22,295 Reputation points Volunteer Moderator
    2022-03-22T22:35:40+00:00

    You'll need to examine the relationships between tables in your relational database application so that you can append data to the tables on the one side of relationships first. In this case that looks to be the orders table. However, it has a dependency on the customer table, does it not? That means only orders for existing customers can be appended. How is that resolved for this business? If all of the orders in your Excel file are from existing customers, that won't be an impediment, but that's up to your analysis since we can't see the data in question.

    An append query needs to be set up to append only new orders, not all ready in the Access orders table. It looks like that might be controllable through the OrderNum field since it is included in the import file and in the destination file, so something like

    SELECT * FROM tempImportFromExcelTable TE

    LEFT OUTER JOIN tblOrdersMain OM

    ON TE.OrderNum = OM.OrderNum

    WHERE OM.OrderNum Is Null

    Verify that returns the results you need, then turn it into an INSERT query to add only the new Orders.

    Then you can repeat that with the Details table, except that the new details will only be for records that match the new Orders.

    0 comments No comments
  5. Anonymous
    2022-03-22T22:42:56+00:00

    I should've included the below screenshot. The table "OORLatestUpload" is the imported xlsx file. The "tblOrdersMain" and "tblOrdersDetails" need to be updated with new records from the xlsx file. The xlsx table has "Material #" which is in tblMaterials but doesn't need to be added to the child table as it should already exist. Every query I made doesn't seem to work. This is a query with the xlsx table and tblOrderDetails:

    INSERT INTO tblOrderDetails ( OrderLine, OrderedSalesQty, ConfirmedSalesQty, PricingQty, ProductInvoicePrice, Truckloads48, PlannedDelDate, PlantDesc, DelGrp )

    SELECT OORLatestUpload.[Order Ln], OORLatestUpload.[Ordered Sales Qty], OORLatestUpload.[Confirmed Sales Qty], OORLatestUpload.[Pricing Qty], OORLatestUpload.[Product Invoice Price], OORLatestUpload.[Truckloads (48')], OORLatestUpload.[Planned Del Dt], OORLatestUpload.[Plant Desc], OORLatestUpload.[Del Grp]

    FROM tblOrderDetails INNER JOIN OORLatestUpload ON tblOrderDetails.OrderLine = OORLatestUpload.[Order Ln];

    I'm getting the wrong total number of records (more than what is in the xlsx table) and then they all have validation rule violations. The excel file I have has no formatting conducive of good database design.

    0 comments No comments