I'm ready to give up!!!!!!
I have a front and back end of a simple database. Everytime I open it up from a different computer on our network the table links are broken so I want it to check for this and prompt for the location of the back end.
I have some code that tries to refresh the link and calls a separate sub if the link is broken. The code for the sub is below:
Private Sub ResetLinks()
Dim db As DAO.database
Dim recLinkTables As DAO.Recordset
Dim tbdTemp As DAO.TableDef
Dim strTemp, strPath As String
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
fd.Show
'retrieve the path from the file dialog
strPath = fd.SelectedItems(1)
MsgBox strPath
Set db = CurrentDb
Set recLinkTables = db.OpenRecordset("tblLinks", dbOpenDynaset)
If recLinkTables.RecordCount > 0 Then
With recLinkTables
.MoveFirst
While Not .EOF
db.TableDefs(!TableName).Connect = ";DATABASE =" & strPath
db.TableDefs(!TableName).RefreshLink
.MoveNext
Wend
End With
End If
End Sub
I have had message boxes in places returning my connection strings etc. In short, the .connection property houses the original database and path early in the sub. The .connection is set to the new database and path just prior to the line that should refresh the link. The .refreshlink call returns an error number 3001 "Invalid Argument".
If I look at the .connection property when the links are first being tested for refresh, it is identical to the one that gives the problem later. (I have simply been renaming the back end file by one letter each time to break the link and test the subs)
Any suggestions?????
I have a front and back end of a simple database. Everytime I open it up from a different computer on our network the table links are broken so I want it to check for this and prompt for the location of the back end.
I have some code that tries to refresh the link and calls a separate sub if the link is broken. The code for the sub is below:
Private Sub ResetLinks()
Dim db As DAO.database
Dim recLinkTables As DAO.Recordset
Dim tbdTemp As DAO.TableDef
Dim strTemp, strPath As String
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
fd.Show
'retrieve the path from the file dialog
strPath = fd.SelectedItems(1)
MsgBox strPath
Set db = CurrentDb
Set recLinkTables = db.OpenRecordset("tblLinks", dbOpenDynaset)
If recLinkTables.RecordCount > 0 Then
With recLinkTables
.MoveFirst
While Not .EOF
db.TableDefs(!TableName).Connect = ";DATABASE =" & strPath
db.TableDefs(!TableName).RefreshLink
.MoveNext
Wend
End With
End If
End Sub
I have had message boxes in places returning my connection strings etc. In short, the .connection property houses the original database and path early in the sub. The .connection is set to the new database and path just prior to the line that should refresh the link. The .refreshlink call returns an error number 3001 "Invalid Argument".
If I look at the .connection property when the links are first being tested for refresh, it is identical to the one that gives the problem later. (I have simply been renaming the back end file by one letter each time to break the link and test the subs)
Any suggestions?????