Here is what I use to switch a front-end between two servers (development and production). I have a local settings table with a boolean field (VerifyLinks) to flag that the front-end needs to be re-linked. I call the vcVerifyMySQLLinks function on the very first line of my AutoExec macro (using RunCode). So when I need to force all front-ends to relink (i.e. for update purposes) I would check the VerifyLinks field, set the connection string in my ConnectionString field (these are both in a local hidden SettingsTable).
Code:
Public Function vcVerifyMySQLLinks()
Dim boVerify As Boolean
On Error Resume Next
boVerify = DLookup("[VerifyLinks]", "[SettingsTable]")
'refresh links and reset flag
If boVerify = True Then
vcLinkTableDefs
DoCmd.SetWarnings False
DoCmd.RunSQL "UPDATE [SettingsTable] SET [SettingsTable].[VerifyLinks] = False"
DoCmd.SetWarnings True
End If
End Function
Public Sub vcLinkTableDefs()
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim strNewConnectionString As String
On Error Resume Next
Set dbs = CurrentDb()
' Loop through TableDefs collection, only processing
' the table if it already has a Connection property.
' (all other tables are local ... not linked)
For Each tdf In dbs.TableDefs
If tdf.Connect <> "" Then
strNewConnectionString = DLookup("[ConnectionString]", "[SettingsTable]")
If tdf.Connect <> strNewConnectionString Then
tdf.Connect = strNewConnectionString
tdf.RefreshLink
End If
End If
Next
End Sub
Please note that you cannot have a default bound form set as the opening form if using this approach. I open my "switchboard" in the same autoexec macro on the line following the one the checking for/re-linking.
For MySQL I use the following connection string (stored in the ConnectionString field using a password Input Mask):
ODBC;DRIVER={MySQL ODBC 5.1 Driver};SERVER=YourServer;DATABASE=YourDatabaseNam e;PORT=3306;UID=YourUser;PWD=YourPassword;Option=4 194314
Cheers,
Vlad