Change source of linked tables - Solved!
I have a db (mydb.mdb) with a linked table ("tbl_one"), currently pointing to a table with the same name in an access db called "sourcedb-feb". I'd like to use vba to open a dialog box for the user to select a new source (like "sourcedb-mar") and to alter the table's link accordingly (the table name will be the same in the new source database as well).
From searching here and msdn I've got the following for the dialog box:
but all I've been able to turn up re: links are a couple of snippets of code I don't understand how to use, namely:
and from msdn
If anyone could give me an idea of how to put this together (like, in the last bit of code, does "AccessTable" refer to a table in my db, or is it to tell access I'm going to be linking to an access table??) I'd be really grateful - cheers!
I have a db (mydb.mdb) with a linked table ("tbl_one"), currently pointing to a table with the same name in an access db called "sourcedb-feb". I'd like to use vba to open a dialog box for the user to select a new source (like "sourcedb-mar") and to alter the table's link accordingly (the table name will be the same in the new source database as well).
From searching here and msdn I've got the following for the dialog box:
Code:
Dim FileChosen As String
With Application.FileDialog(1)
.AllowMultiSelect = False
.Filters.Add "DataSources", "*.mdb", 1
.InitialFileName = "\\path\sourcedb-*.mdb"
.Title = "Select Source Database"
.Show
End With
If Application.FileDialog(1).SelectedItems.Count = 1 Then
FileChosen = Application.FileDialog(1).SelectedItems(1)
Else
MsgBox ("No file selected.")
End If
Code:
CurrentDb().TableDefs(TableName).SourceTableName
Code:
ConnectOutput OpenDatabase("mydb.mdb",_
"AccessTable", _
";DATABASE= " & FileChosen & ", _
"tbl_one"
Last edited: