Update Access DB from Excel Sheet

Posted on 2011-10-10
Last Modified: 2012-05-12
Hey Experts!!

I have a slight problem and I'm really hoping someone can help me.  About a month ago, I exported a query (below) from an Access 2003 DB to Excel. People have been updating it with newer values.

What I need to do now is update the same 3 tables with the updated information from an Excel sheet.  I'm not sure how to go about doing that though. Do I use an "UPDATE" instead of "SELECT" statement? Do I do each table individually?  

Thanks in advance.
SELECT DISTINCT Client.ACT_no, Client.Client, Client.Address, Client.Address2, Client.City, Client.State, Client.Zipplus, Client.County, Client.AREA_Phone, Client.CatSub_ID, Client.Contact_no, Client.notes_id, Client.script, Client.instructor, Client.instructor_phone, Client.user_main, Client.last_user, Client.last_date, Contacts.*, Cat_Sub.*
FROM (Contacts RIGHT JOIN Client ON Contacts.ACT_No = Client.ACT_no) LEFT JOIN Cat_Sub ON Client.CatSub_ID = Cat_Sub.CatSub_ID;

Open in new window

Question by:LZ1
    LVL 84
    If you're not adding new records to those tables, then yes, you'd use an UPDATE statement. The basic syntax is this:

    UPDATE YourTable SET Field1=Value1, Field2=Value2 WHERE YourPrimaryKeyField=PrimaryKeyValue

    Of course, you'll be grabbing this data from the worksheet, so it would look something like this:

    YourConnection.Execute "UPDATE YourTable SET Field1='" & Cells("A1") & "', Field2=#" & Cells("B1") & "# WHERE YourPrimaryKeyField=" & YourPrimaryKeyValue

    My Excel syntax might be rusty, but hopefully that will give you the gist of what to do.

    Also, you would need to update each table individually. If you are ADDING records, and if those tables are related, they would need to be done in order - in other words, you'd have to add the Parent records before the Child records.

    Note also the syntax in the statement above. Access expects Text value to be surrounded in single or double quotes, and expects Date values to be surrounded with hash marks ( # ). In my example above, Field1 is a Text field, and I've surrounded the value for that field with single quotes. Field2 is a Date field, and I've surrounded the values for that field with hash marks.

    LVL 30

    Author Comment

    Hi LSMConsulting. Yes, it's just updating as far as I'm aware but I will verify with the client. So for the Excel sheet, how would I call the file inside the query syntax?
    LVL 84
    What do you mean "call the file"?

    Are you running this in Excel or Access?
    LVL 30

    Author Comment

    The query will be running in Access, as that's where the tables are. But how do I import(for lack of a better term) all of the updated fields?
    LVL 84

    Accepted Solution

    Sorry ... it seems that you have an external worksheet, and you need to now update the values in access based on those new values.

    Is this a "one time" thing - that is, you'll update this now, and won't have to do it again (or won't do it again for quite some time), or is this an on-going update process?

    If it's a one time thing, the simplest way would be to simply Import that Excel worksheet into Access, then use standard VBA processes to get to the data in the (now imported) table. In fact, you may be able to do this entirely with the query designer, depending on the structure of the incoming data.
    LVL 30

    Author Comment

    This will be a one time thing LSMConsulting. However, I'd much rather hand code it if I can.  I suppose I could use the query designer though. The structure of the data should be good though.

    So my steps, as I understand you, should be this:
    1) Import my Excel sheet into a whole new table and name it
    2) Then using an UPDATE Syntax, run the same query as the SELECT statement and reference that new table.
    3) I should be done???

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
    CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
    In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

    734 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

    24 Experts available now in Live!

    Get 1:1 Help Now