+ Reply to Thread
Results 1 to 5 of 5

Adding to existing VBA to connect Access DB to Excel sheet

  1. #1
    Spammer
    Join Date
    11-21-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    387

    Adding to existing VBA to connect Access DB to Excel sheet

    I am very new to VBA.... this is the first file that I have ever created that uses it.... so I know I have a lot to learn still... and am trying to learn as I go.

    Im hoping that somebody can help me with this....

    The first tab that opens in a worksheet directs users to select the location of an access DB.

    The information inside of the DB updates once, maybe twice a year. So upon that first connection to the DB, before anything else is calculated in the workbook, I need a macro to check the Last Update "date" on the Surcharge tab. That date will reference a field inside the "Date" table in the access DB. If the dates do not match, then I need data in excel tabs DAS, UPS Tarriff and Surcharge to update.

    If the dates match, then nothing needs to happen and we can proceed as normal.

    DB Tables that would need to be referenced for updates are:

    NDAS, NDA, 3DS, 2DA, GND, Surcharge, Date, DAS

    Info from tables NDAS, NDA, 3DS, 2DA, GND would show up in the "UPS Tariff" worksheet
    Info from table Surcharge would should up on the "Surcharge" worksheet
    Info from Date table should show up on the "surcharge" worksheet
    Info from the DAS table would show up on the "DAS" worksheet.

    Thank you in advance for your help. Looking forward to figuring this out.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Adding to existing VBA to connect Access DB to Excel sheet

    To check a single value from the database I would read the data into an array and then cross reference the 1st element of the array (alternatively you could drop it into a cell on a worksheet).

    Whenever Im working with ADO I use a couple of different Functions to save rewriting the whole connection strings etc, below is my example one to read data into an Array

    Please Login or Register  to view this content.
    Then whenever I want to pull in data I simply call the Sub like so:
    Please Login or Register  to view this content.
    If someone has helped you then please add to their Reputation

  3. #3
    Spammer
    Join Date
    11-21-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    387

    Re: Adding to existing VBA to connect Access DB to Excel sheet

    Thank you for the response... that did go a little over my head, however.

    If i am understanding, the above code would check to see if the "date" in the DB, matches the "date" on the excel sheet... is this correct??

  4. #4
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Adding to existing VBA to connect Access DB to Excel sheet

    Quote Originally Posted by snuffnchess View Post
    Thank you for the response... that did go a little over my head, however.

    If i am understanding, the above code would check to see if the "date" in the DB, matches the "date" on the excel sheet... is this correct??
    No, the above code runs whatever SQL you give it and outputs the results to an array.

    You would then compare the values using something like:

    Please Login or Register  to view this content.

  5. #5
    Spammer
    Join Date
    11-21-2014
    Location
    California
    MS-Off Ver
    2010
    Posts
    387

    Re: Adding to existing VBA to connect Access DB to Excel sheet

    So how would the code look like to Just have a check of

    If DB table name Date does not equal Surcharge!B3

    return message "need to update"

    If you can help me figure out this part of it, I think i can learn from that code to make the rest of the tables update.

+ 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. Connect from excel to access database on internet-server
    By michiel soede in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-16-2015, 02:50 PM
  2. [NEED HELP] How to connect an Excel with an Access DB
    By basubdd in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-04-2013, 03:09 PM
  3. excel template connect to access database???
    By ddaudi8 in forum Excel General
    Replies: 1
    Last Post: 04-16-2009, 03:40 PM
  4. connect excel to access database
    By associates in forum Excel General
    Replies: 13
    Last Post: 11-13-2007, 06:34 PM
  5. adding data with formula to existing table in ms access
    By nataliem in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-25-2007, 03:46 AM
  6. [SOLVED] Help with using ADO to connect Excel to Access
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-29-2006, 05:30 AM
  7. Replies: 0
    Last Post: 04-25-2006, 03:15 PM

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