Attached is code to link tables in databases that are in a folder. My variable for the source in the DoCmd.transferD atabase code Dir(strPath & rst!FolderName) is not working right. I want to loop through the db names to link the tables.
each db has only 1 table which is named the same as the db. We have a macro that pulls all the db names from the folder into a table called tblDirectory into the field FolderName (that's a bit misleading, I know). I have very little VB knowledge. I'd appreciate any detailed instructions.
each db has only 1 table which is named the same as the db. We have a macro that pulls all the db names from the folder into a table called tblDirectory into the field FolderName (that's a bit misleading, I know). I have very little VB knowledge. I'd appreciate any detailed instructions.
Code:
Function LinkTable()
Dim rst As DAO.Recordset
Dim strPath As String
Dim strFile As String
strPath = "D:\Temp\Testing\"
Set rst = CurrentDb.OpenRecordset("tblDirectory", dbOpenTable)
Do Until rst.EOF
'ensure exist
strFile = Dir(strPath & rst!FolderName)
If Len(Dir(strPath & rst!FolderName)) > 0 Then
DoCmd.TransferDatabase acLink, "Microsoft Access", Dir(strPath & rst!FolderName), acTable, rst!FolderName, rst!FolderName, False
End If
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
End Function
Comment