Results 1 to 12 of 12
  1. #1
    kagoodwin13 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Feb 2012
    Posts
    181

    Schedule daily overnight import or refresh with ODBC connection

    I am attempting to use Access as a back-end to Tableau, a business intelligence reporting tool.

    I am able to connect my data sources to Access through an ODBC connection. I can either do a one-time import or set up a linked table. However, what I would really like is to set up a scheduled refresh or import of data. There is too much data to query directly through linked tables - it would be too slow to be convenient to use. It would be nice if it could refresh overnight (every night at 9 pm for example) so that we can have fresh data daily.

    If I am thinking about this correctly, I would have to do the following:
    1. Create linked tables (refresh each time they are opened)
    2. Create corresponding static tables
    3. Write a VBA command to update static tables from linked tables
    4. Include some sort of scheduling component inside the VBA command




    Does anyone know a good place to get started with the fourth step? Or am I thinking about the process all wrong to begin with?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I use a VBScript file that has code to open db and run a procedure in a general module.

    Windows Task Scheduler has item to run the VBScript on a set schedule.

    Example code:

    Dim accessApp
    set accessApp = CreateObject("Access.Application")
    accessApp.OpenCurrentDataBase("your file path to db\databasename.accdb")
    accessApp.Run "your procedure name"
    accessApp.Quit
    set accessApp = nothing

    Use Notepad to create the text file. Rename it to change file extension from txt to vbs.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    kagoodwin13 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Feb 2012
    Posts
    181
    That's a great solution! I'm assuming I'll have to leave my computer running overnight to complete the task?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I think so for the Task Scheduler to work and certainly if the db file path is on your computer. I never shut down.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It sounds like this is more of a Tableau question, unless you're saying you can link to Tableau from Access and want to push the data from Access. If so, it shouldn't be hard. I'd create a separate db with a VBA function that performed your export, call that function from an autoexec macro, and run the db from Windows Scheduled Tasks.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Geez, this is what happens when you get distracted while typing. Sorry.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    kagoodwin13 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Feb 2012
    Posts
    181
    Any tips for finding or naming the procedure? I've done lots of Google searching to no avail. I am assuming it is not "Command0" or "Command0_Click" because those have not worked in the vbs script.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You'd create a public function in a standard module (they can't have the same name). You'd use the name of the function. If you're unfamiliar:

    http://www.baldyweb.com/Function.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    kagoodwin13 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Feb 2012
    Posts
    181
    Success!

    Recap of process:

    1. Create linked tables
    2. Create corresponding static tables
    3. Set primary key in static tables
    4. Write a public function inside a separate module (with different name than the function) with SQL append command to copy linked tables to static tables. Primary key in static tables will prevent duplication. See code below.
    5. Use VBS script to call VBA. See code below.
    6. Use Windows Task Scheduler to run VBS script at desired time/frequency


    Module code to run SQL append command
    Code:
    Option Compare Database
    
    Public Function ODBCRefresh()
    
    DoCmd.SetWarnings False
    
        DoCmd.RunSQL "DELETE * FROM StaticTable"
        DoCmd.RunSQL "INSERT INTO StaticTable ( Field1, Field2, Field3 ) SELECT LinkedTable.Field1, LinkedTable.Field2, LinkedTable.Field3 FROM LinkedTable;"
    
    DoCmd.SetWarnings True
    
    
    End Function

    VBS script
    Code:
    Dim accessApp
    set accessApp = CreateObject("Access.Application")
    accessApp.OpenCurrentDataBase("filepath\DatabaseName.accdb")
    accessApp.Run "ODBCRefresh"
    accessApp.Quit
    set accessApp = nothing

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Would you also want to empty the static table first?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Probably not significant, but the procedure does not have to be a Function, it can be a Sub.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    kagoodwin13 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Feb 2012
    Posts
    181
    Yes, it would be best to empty the static table first.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 03-02-2015, 09:44 AM
  2. Replies: 1
    Last Post: 10-22-2014, 12:44 PM
  3. Replies: 5
    Last Post: 10-25-2011, 08:01 AM
  4. Refresh ODBC Connection with new UserID and Password
    By jgelpi16 in forum Programming
    Replies: 1
    Last Post: 06-20-2011, 10:13 AM
  5. ODBC connection
    By avicenna in forum Import/Export Data
    Replies: 2
    Last Post: 08-02-2010, 02:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums