Cool. Please post. I'm sure the original poster would be very
interested. I'm certainly interested, as I have this task ahead of me.
Actually, from Hyo's post downthread, it looks as though these linked
tables really belong in one mdb file. Still, here is the old fashioned
DAO version:
' use dao to update the tabledef connect strings
'
' simplified script to update tabledef links using ADOX
' No error trapping! For demonstration only!!
'
'
' DAO Objects
'
dim dbe ' dbengine
dim db ' database
dim ws ' workspace
dim tdf ' tabledef
dim connectString ' connection string
dim mdbPath ' path and file of mdb file
const dbAttachedTable = &H40000000
' these consts should really be parameterised...
mdbPath = "C:\My Data\uncle.mdb"
connectString = ";DATABASE=C:\Access\db1.mdb"
' make a new dbengine to hold everything
Set dbe = CreateObject("DAO.DBEngine.36")
' open the database exclusively and read-write
set db = dbe.Workspaces(0).OpenDatabase(mdbPath, True, False)
' iterate the tabledefs
for each tdf in db.TableDefs
' we only want attached tables
if tdf.Attributes And dbAttachedTable Then
' helpful for debugging
wscript.echo "Updating " & tdf.Name
' set it and force the update
tdf.Connect = connectString
tdf.RefreshLInk
end if
next ' tdf
' tidying up
db.Close
'### end of script ###
and here is the ADOX version, which I just put together as an exercise...
' use ado to update the tabledef connect strings
'
' simplified script to update tabledef links using ADOX
' No error trapping! For demonstration only!!
'
' Tim Ferguson 2005
'
'
' These consts should really be parameterised!
'
const pathToFrontEnd = "C:\Documents and Settings\Ferguson\My Documents
\My Data\uncle.mdb"
const pathToBackEnd = "C:\Documents and Settings\Ferguson\My Documents
\Programming\Access\copy of db1.mdb"
'
' Don't believe the property "Jet OLEDB:Create Link" as it's used
' for querydefs too, and setting a path on them raises an error
'
' Poke the new address straight into the Link Datasource property
'
const propertyName = "Jet OLEDB:Link Datasource"
'
' ADOX objects
'
dim cat ' as catalog
dim tbl ' as table
dim prp ' as property
'
' Obvious
set cat = createobject("ADOX.Catalog")
' Obvious too
cat.activeconnection = "Provider=Microsoft.Jet.OLEDB.4.0" & _
";Data Source=" & pathToFrontEnd
' iterate through all the tables,
for each tbl in cat.tables
' look for a non-empty property
' all Access tables and querydefs appear to have this property
' set, even if it is only to an empty string
set prp = tbl.properties(propertyName)
if len(prp.Value)>0 Then
' warming for the user
wscript.echo "updating " & tbl.Name
' poke in the new value
prp.Value = pathToBackEnd
end if
next ' tbl
' all done; close down
set cat = nothing
'### end of script ###
Hope it helps
Tim F