Hi guys,
I am impressed today to see that my post has sparked some interest. Since yesterday I have come up with a solution that seems to be working, now, I don't know how technically sound it is but so far so good.
Here's what I did:
I created an unbound field on a form and used the Browse() function from the relink on startup module that is found in the solutions database.
Then I made another button on the form and put this code in the on click event:
Private Sub cmdLinkNew_Click()
On Error GoTo Err_ChangeLinks
Dim DB As DAO.Database
Dim td As DAO.TableDef
Set DB = CurrentDb
For Each td In DB.TableDefs
If Len(td.Connect) > 0 Then
td.Connect = ";DATABASE=" & Trim([Forms]![frmChangeLink]![NewFileName])
td.RefreshLink
End If
Next
MsgBox "You have successfully connected to a new data file.", vbInformation
DoCmd.Close acForm, Me.Name
DoCmd.Close acForm, [Forms]![Menu].Name
DoCmd.OpenForm "Menu"
Exit_ChangeLinks:
Exit Sub
Err_ChangeLinks:
MsgBox "The data file you have chosen is not appropriate! Please choose a different data file name.", vbInformation
Me.NewFileName.SetFocus
Resume Exit_ChangeLinks
End Sub
It does seem to work well, although I don't fully understand all the code commands and reasons for them, I have begged, borrowed and stole code form all over the place to get to this point.
What do you think? I am very interested to hear your feedback.
Rachael
I am impressed today to see that my post has sparked some interest. Since yesterday I have come up with a solution that seems to be working, now, I don't know how technically sound it is but so far so good.
Here's what I did:
I created an unbound field on a form and used the Browse() function from the relink on startup module that is found in the solutions database.
Then I made another button on the form and put this code in the on click event:
Private Sub cmdLinkNew_Click()
On Error GoTo Err_ChangeLinks
Dim DB As DAO.Database
Dim td As DAO.TableDef
Set DB = CurrentDb
For Each td In DB.TableDefs
If Len(td.Connect) > 0 Then
td.Connect = ";DATABASE=" & Trim([Forms]![frmChangeLink]![NewFileName])
td.RefreshLink
End If
Next
MsgBox "You have successfully connected to a new data file.", vbInformation
DoCmd.Close acForm, Me.Name
DoCmd.Close acForm, [Forms]![Menu].Name
DoCmd.OpenForm "Menu"
Exit_ChangeLinks:
Exit Sub
Err_ChangeLinks:
MsgBox "The data file you have chosen is not appropriate! Please choose a different data file name.", vbInformation
Me.NewFileName.SetFocus
Resume Exit_ChangeLinks
End Sub
It does seem to work well, although I don't fully understand all the code commands and reasons for them, I have begged, borrowed and stole code form all over the place to get to this point.
What do you think? I am very interested to hear your feedback.
Rachael