+ Reply to Thread
Results 1 to 15 of 15

Overwrite access database from excel table using VBA

  1. #1
    Registered User
    Join Date
    06-29-2018
    Location
    India
    MS-Off Ver
    2016
    Posts
    6

    Question Overwrite access database from excel table using VBA

    I've searched this website for my question, but unable to locate solution. I'm a beginner for excel VBA, Need some help help in updating old data in access database with new data from excel spreadsheet using excel-VBA.

    From internet i've created the following steps.

    Step1 : Uploading initial data (I've got a working VBA macro for this step):

    Upload excel table:
    Upload.JPG

    Step 2 : Downloading data from access to excel (I've working VBA macro for this step)

    Download from access:
    Download.JPG

    Step 3 : Now, I want to overwrite entire access table with revised data from excel table. I'm unable to locate macro for this step.

    Overwrite from excel to access:
    Overrite.JPG

    Please help me with a VBA program or any website link for this step.
    I've attached sample excel and access file in a zip foler.
    Attached Files Attached Files

  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: Overwrite access database from excel table using VBA

    When you say "overwrite" do you want to only update the items you have in red? or completely erase the table and re-populate it?
    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 Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Overwrite access database from excel table using VBA

    I you just want to update those fields, then this would work...:

    Please Login or Register  to view this content.
    PS, welcome to the forum

  4. #4
    Registered User
    Join Date
    06-29-2018
    Location
    India
    MS-Off Ver
    2016
    Posts
    6

    Re: Overwrite access database from excel table using VBA

    I have 10000 of records in my access table, in that I retrieved some records (Eg : 10 records) using filters and change the values and want to overwrite only those 10 records in existing access database using ID number.

    Irrespective of the changes in any column, I want to replace the entire row of a particular ID #
    Last edited by n21crowns; 07-03-2018 at 04:08 AM.

  5. #5
    Registered User
    Join Date
    06-29-2018
    Location
    India
    MS-Off Ver
    2016
    Posts
    6

    Re: Overwrite access database from excel table using VBA

    Hi Arkadi, Thanks for your time,
    I want to update the entire records displayed in that latest table, no specific columns, users may change any columns at any time.
    Hence i want this program to update the entire table

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

    Re: Overwrite access database from excel table using VBA

    The principle is the same, you just need to expand the sql statement to include all columns and cell references. I'll try to send something updated this afternoon.

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

    Re: Overwrite access database from excel table using VBA

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    06-29-2018
    Location
    India
    MS-Off Ver
    2016
    Posts
    6

    Re: Overwrite access database from excel table using VBA

    Thanks for your program, In real case senario, I've more than 150 columns in the table, Do i need to declare all the column names in the SQL statement, if there anyway, we can simplify it??

    FYI - For fresh uploading, I didn't declare any column names.

    Program given below for upload new data from excel to access. Can we get anything like this for updating existing data??

    Please Login or Register  to view this content.
    -------------

    When i tried with your program, getting error in the following line (screen shot attached below). Thanks in advance for sorting out the error.

    Debug.JPG
    Last edited by alansidman; 07-05-2018 at 03:33 AM. Reason: code tags

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

    Re: Overwrite access database from excel table using VBA

    About the error: I tested it with the sample database you provided... are you running the code on the same database and excel file that you uploaded originally?

    As far as simpifying, are the Excel columns in the same order as the database fields? We could probably come up with a loop to update recordset fields and do an update, rather than using sql statements. Could you create a copy of the real table? Doesn't need more than one or 2 dummy records, so we can test it out a little better.

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

    Re: Overwrite access database from excel table using VBA

    Actually nevermind the sample database... give this a shot:

    Please Login or Register  to view this content.
    You could add a check before updating that the recordcount of rset1 is 1. If it is 0 then no matches were found for that ID, and if it is >1 then you have multiple records with the same ID. However, if it is a straight download, and the ID column has unique values only, then you should be fine.
    Last edited by Arkadi; 07-04-2018 at 09:21 AM.

  11. #11
    Registered User
    Join Date
    06-29-2018
    Location
    India
    MS-Off Ver
    2016
    Posts
    6

    Re: Overwrite access database from excel table using VBA

    Code Sub update_db_v2() worked well for the sample database. When i tried it with real database, getting some error.

    I've attached the real database for your review.

    Thanks for all your support
    Last edited by n21crowns; 07-05-2018 at 12:49 AM.

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

    Re: Overwrite access database from excel table using VBA

    Which sheet in that new book is the one used to update the database?
    And what error are you getting?
    Last edited by Arkadi; 07-04-2018 at 11:10 AM.

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

    Re: Overwrite access database from excel table using VBA

    Well, wasn't getting an answer, so I guessed it is the Import sheet?

    A few things... ID is now column B not A, so that needed updating. Also, the loop now needs to start at 10 not 2, since that is the first row with data:

    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    06-29-2018
    Location
    India
    MS-Off Ver
    2016
    Posts
    6

    Re: Overwrite access database from excel table using VBA

    Due to time zone difference, I'm unable to reply you, when you asked.

    As you said, I made error with the loop (needs to start at 10 not 2). Everything working perfect right now.

    Thanks for all your great work.....

  15. #15
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,937

    Re: Overwrite access database from excel table using VBA

    @n21crowns

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    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

+ 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. Comparing an MS Access database table columns to an excel spreadsheet
    By 1aaaaaaaaaaaaaaa in forum Tips and Tutorials
    Replies: 0
    Last Post: 05-31-2018, 06:33 PM
  2. Link excel table to access database
    By c00ly81 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-02-2016, 09:56 AM
  3. Access Database and Excel Pivtot Table Issue
    By jefflab1 in forum Excel General
    Replies: 0
    Last Post: 08-11-2015, 11:05 PM
  4. Replies: 2
    Last Post: 07-05-2013, 09:37 AM
  5. Export Excel data into Access table - overwrite table data
    By Jonsocks in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-08-2012, 12:05 PM
  6. Deleting all records in a access database table from Excel
    By Dave31 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-29-2008, 02:18 PM
  7. Link an excel worksheet to an access database table?
    By w97667 in forum Excel General
    Replies: 1
    Last Post: 04-05-2006, 02:25 PM

Tags for this Thread

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