How to refresh link to open database

  • Thread starter Thread starter Helge V. Larsen
  • Start date Start date
H

Helge V. Larsen

I have the following VBA that is used to refresh all links to linked tables.
It functions correctly when the database that I link to is closed.
But when it is opened (by me) I get the error message
"The database has been placed in a state by user 'Admin' on machine
'PC-12345' that prevents it from being opened or locked.".
I get the error message most times, but not always. I cannot find out when.
Perhaps something about timeout ?

What can I do to prevent the error ?

Helge
Please also answer directly to Helge.V.Larsen/Remove this/@/and
this/Risoe.DK


Sub Refresh_Links

Dim aTabDef As Object
Dim Cannot_Refresh as Boolean

Cannot_Refresh = False
For Each aTabDef In Application.CurrentDb.TableDefs
If aTabDef.Connect <> "" Then
On Error GoTo Lab_Cannot_Refresh
aTabDef.RefreshLink
On Error GoTo 0
End If
Next aTabDef

Lab_Cannot_Refresh:
Cannot_Refresh = True
' Error trapping code placed here.

End Sub
 
You possibly have a form opened that is directly or indirectly (through a
query) bound to data in one of the tables you are trying to refresh the link
to.

I usually write my code to work ASAP after opening the database front-end,
and before any data is every accessed.
 
Do you open it shared sometimes, and exclusive sometimes?

Or do you open it shared, and promote to exclusive by
looking at VBA or Form Design?

Or do you open it shared, and promote to exclusive by
using a form filter, or something like that?

(david)
 
Back
Top