+ Reply to Thread
Results 1 to 5 of 5

Excel VBA to update table in Access 2013

  1. #1
    Registered User
    Join Date
    07-27-2015
    Location
    England
    MS-Off Ver
    Office 2010
    Posts
    40

    Excel VBA to update table in Access 2013

    Hello

    I have an Excel 2013 spreadsheet with multiple tables (1 table in each worksheet).

    Each of these tables mirrors the data I have in an Access 2013 database.

    The data is duplicated into Access 2013 because there are some Query Reports which are run (due to a few many-to-many relationships between the tables) and subsequently exported to Excel 2013!

    I’d like to be able to update one or more of these tables in excel, click a button (one button per table) and then for the data to be updated in the Access 2013 table.

    I’ve thought about the best way of doing this & I think the simplest method would be for the VBA code to open the table in the Access 2013 database, delete all of the records (but keeping the column headers), and then import all of the rows from the Excel table.

    This would ensure that the tables in Access 2013 fully mirror the tables in Excel 2013 whilst leaving the relationships between the tables intact.

    Does anyone have any sample code which I could perhaps tweak?

    Thanks in advance

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Excel VBA to update table in Access 2013

    Hi Sumif, here's some basic code to get you started as far as opening a database connection, and deleting records from the table: (requires you to add a reference to Microsoft ActiveX Data Objects Library (I use 6.1 generally))

    Its just a quick sample code, and I didn't test but use code like this quite often so it ought to work.

    Please Login or Register  to view this content.
    Last edited by Arkadi; 12-21-2015 at 10:38 AM.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,703

    Re: Excel VBA to update table in Access 2013

    An alternative is to link the Excel worksheets to Access. In this manner, the linked worksheets appear in the database as tables and can then be used as record sources for your queries. Each time you update the worksheets, the database is automatically updated because they are linked. No need for VBA or importing required. It is all in real time.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Registered User
    Join Date
    07-27-2015
    Location
    England
    MS-Off Ver
    Office 2010
    Posts
    40

    Re: Excel VBA to update table in Access 2013

    Thanks Arkadi, i'll work with your code & post back how i get on.

  5. #5
    Registered User
    Join Date
    07-27-2015
    Location
    England
    MS-Off Ver
    Office 2010
    Posts
    40

    Re: Excel VBA to update table in Access 2013

    Thanks for the tip Alan

    I would have preferred to link the Excel worksheets to Access but unfortunately i've had issues creating the right relationships between the tables once they've been imported (probably because my data is structured in the way Access would like it).

    However, i already have an Access database with the correct relationships between the tables but it just needs to be updated.

    It's weird that i'm not using what should be the simpler approach but it's most probably because of my lack of knowledge of Access (sorry!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Excel 2013, can't access VBA help
    By Danino in forum Excel General
    Replies: 4
    Last Post: 07-06-2015, 10:31 AM
  2. Excel 2013 and Access 2013 as Pivot Table External Data Source
    By Grimnebulin in forum Access Tables & Databases
    Replies: 1
    Last Post: 05-27-2015, 02:13 PM
  3. Trying to update an access table from Excel based on unique ID. rst.Update not working
    By Newbie0924 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-22-2015, 04:15 PM
  4. Replies: 1
    Last Post: 12-02-2014, 05:46 AM
  5. [SOLVED] update table in access from excel using sql
    By specialk9203 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-19-2014, 03:44 PM
  6. Update Access Table from Excel using DAO
    By vish2025 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-15-2010, 06:02 AM
  7. Update & Append Access Table Using Excel Macro - ADO
    By erock24 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-19-2010, 04:49 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1