How can I get a linked Excel table to update automatically? (1 Viewer)

Mr. Southern

Registered User.
Local time
Today, 00:02
Joined
Aug 29, 2019
Messages
90
Hello,

I have a linked Excel Table that needs to be refreshed every day. I have built a database off of this and a few other tables. Is there any way that I could put a button on a form that would refresh the excel files?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:02
Joined
Oct 29, 2018
Messages
21,467
Hi. Refreshed from where? Where is the data coming from?
 

YouMust

Registered User.
Local time
Yesterday, 22:02
Joined
May 4, 2016
Messages
106
You can link your excel document to the the database and set excel to refresh.

open excel > data > get external data > from other sources > from data connection wizard > ODBC connection > select your db and your required table.


you can then go to properties and select how ofter you'd like excel to update from the db
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:02
Joined
Oct 29, 2018
Messages
21,467
theDBguy,

The Excel spreadsheet is pulling data from various ODBC drivers.
Hi. Thanks for the clarification. Did the above explanation from YouMust help?
 

Mr. Southern

Registered User.
Local time
Today, 00:02
Joined
Aug 29, 2019
Messages
90
You can link your excel document to the the database and set excel to refresh.

open excel > data > get external data > from other sources > from data connection wizard > ODBC connection > select your db and your required table.


you can then go to properties and select how ofter you'd like excel to update from the db

YouMust,

I dont know if I am reading this wrong but I want to clarify that I have a Excel spreadsheet that gets updated daily. I have then linked this spreadsheet into Access to build forums and reports off of it. The excel spreadsheet is not getting data from my db.
 

Mr. Southern

Registered User.
Local time
Today, 00:02
Joined
Aug 29, 2019
Messages
90
Hi. Thanks for the clarification. Did the above explanation from YouMust help?

No. I am not creating the excel spreadsheet from an access db. It is the other way around. I am creating forums and reports from a linked excel table.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:02
Joined
Oct 29, 2018
Messages
21,467
No. I am not creating the excel spreadsheet from an access db. It is the other way around. I am creating forums and reports from a linked excel table.
Hi. I don't think that's what he said. He said to open the Excel spreadsheet in Excel and set the Refresh Rate there. The "db" he's referring to is the ODBC source, not Access.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 00:02
Joined
Feb 28, 2001
Messages
27,167
You said:

The Excel spreadsheet is pulling data from various ODBC drivers.

There is this little "gotcha" about Excel tables linked to Access. You cannot update them from Access because as linked objects, they are read-only. Grabbing data from a linked spreadsheet? No biggie. Updating linked spreadsheet from Access? Biggie!

You could in theory trigger the update from Access - if and ONLY if you open an Excel application object to that workbook and manipulate it through the app object.
 

Mr. Southern

Registered User.
Local time
Today, 00:02
Joined
Aug 29, 2019
Messages
90
Hi. I don't think that's what he said. He said to open the Excel spreadsheet in Excel and set the Refresh Rate there. The "db" he's referring to is the ODBC source, not Access.

theDBguy,

I tried to edit the refresh rate but it doesn't seem to have worked.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:02
Joined
Oct 29, 2018
Messages
21,467
theDBguy,

I tried to edit the refresh rate but it doesn't seem to have worked.
Hi. I just gave it a try, and it seemed to work for me. However, I am not sure what you're exact situation is. In my case, I had to leave the Excel file open to watch if it will auto-refresh, which it did. There's another option in the Properties you could also try and that is the checkbox to "Refresh data when opening the file." I am hoping Access is technically "opening" the file, so maybe it will update the data then.
 

Mr. Southern

Registered User.
Local time
Today, 00:02
Joined
Aug 29, 2019
Messages
90
Hi. I just gave it a try, and it seemed to work for me. However, I am not sure what you're exact situation is. In my case, I had to leave the Excel file open to watch if it will auto-refresh, which it did. There's another option in the Properties you could also try and that is the checkbox to "Refresh data when opening the file." I am hoping Access is technically "opening" the file, so maybe it will update the data then.

theDBguy,

I set up auto-refresh every x minutes but I am going to try to refresh data after opening the file. We will see what happens when use to access db.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:02
Joined
Oct 29, 2018
Messages
21,467
theDBguy,

I set up auto-refresh every x minutes but I am going to try to refresh data after opening the file. We will see what happens when use to access db.
Yes, I set mine to refresh every 1 minute and then waited for one minute and saw the data changed.
 

Mr. Southern

Registered User.
Local time
Today, 00:02
Joined
Aug 29, 2019
Messages
90
Yes, I set mine to refresh every 1 minute and then waited for one minute and saw the data changed.

theDBguy,

I'm going to have to wait for tomorrow morning to see if it changes it. Nothing will be updated until then.
 

Mr. Southern

Registered User.
Local time
Today, 00:02
Joined
Aug 29, 2019
Messages
90
Yes, I set mine to refresh every 1 minute and then waited for one minute and saw the data changed.

It refreshed if its open but im trying to find a way to do it in the background.

I saw:
Code:
Function fRefreshWorkbook() As Boolean
On Error GoTo Err_fRefreshWorkbook
    
    Dim objXL As Object, objWbk As Object, blNewInst As Boolean, _
        strPathToFile As String
    Const c_strFile As String = "Layout.xlsx"
    
    On Error Resume Next
'   See if we can grab an instance of Excel already running
    Set objXL = GetObject(, "Excel.Application")
    If Err <> 0 Then
'       No existing instance of Excel, let's create one
        Set objXL = CreateObject("Excel.Application")
'       Set a flag so we know to destroy the instance after we're done
        blNewInst = True
        Err = 0
    End If
    On Error GoTo Err_fRefreshWorkbook
    
'   Define the Excel file we want to open
    strPathToFile = CurrentProject.Path & "\" & c_strFile
'   Open the file setting the parameter to RefreshLinks = True
    Set objWbk = objXL.Workbooks.Open(strPathToFile, True)
    With objWbk
'       Uncomment following line if links aren't refreshed by the Open() method
'        .RefreshAll
        .Save
        .Close
    End With
Exit_fRefreshWorkbook:
    If Not objWbk Is Nothing Then Set objWbk = Nothing
    If Not objXL Is Nothing Then
        If blNewInst Then objXL.Quit
        Set objXL = Nothing
    End If
    Exit Function
Err_fRefreshWorkbook:
    Select Case Err.Number
    Case Else
        MsgBox "Error No.: " & Err.Number & vbNewLine & vbNewLine & _
               "Description: " & Err.Description & vbNewLine & vbNewLine & _
               "Procedure: fRefreshWorkbook" & vbNewLine & _
               IIf(Erl, "Line No: " & Erl & vbNewLine, "") & _
               "Module: basTest", , "Error: " & Err.Number
    End Select
    Resume Exit_fRefreshWorkbook
End Function


but i cant tell if its working
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:02
Joined
Oct 29, 2018
Messages
21,467
It refreshed if its open but im trying to find a way to do it in the background.
Hi. When you say “background,” are you talking about when the Excel file is closed or just hidden?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 01:02
Joined
Feb 19, 2002
Messages
43,257
Excel is not a database. It should NOT be treated as a database. It would be far better to use an Access FE with proper forms to manage updating the data. If the users need to create reports that Access can't do, then the data can be exported to Excel to let the user slice and dice at will.
 

Micron

AWF VIP
Local time
Today, 01:02
Joined
Oct 20, 2018
Messages
3,478
Is there any way that I could put a button on a form that would refresh the excel files?
Does this mean that the assumption is that once a spreadsheet is linked to Access that it needs to be "refreshed" because it's outdated just because it was linked (e.g.) yesterday? A linked spreadsheet always contains the latest data when the db is opened.

If this is about "refreshing" on a continual basis because the spreadsheet changes (e.g.) every 5 minutes, then there's nothing to do from the Access side of things AFAIC, because Access cannot save a workbook that is already opened by someone else. Excel workbooks are opened exclusively, no?

I'm not sure everyone is on the same page.
 

Users who are viewing this thread

Top Bottom