Hi,
I have over 100 DB in a file path and I'm trying to create a link from one DB. It will be impractical to go thru the link table wizard so I tried this code below. I'm not recieved an error but it doesn't loop thru the directory or it doesn't create all the link. What is missing?
Thanks
Sub LinkAllTblsinDir()
Dim sTblNm As String
Dim sPath As String
Dim sFileNm As String
sPath = "C:\Users\"
'Turn of the Echo to avoid window repaint/refresh
Application.Echo False
sFileNm = Dir(sPath, vbNormal)
Do While sFileNm <> ""
If Right(sFileNm, 3) = “mdb” Then
'sTblNm = Left(sFileNm, Len(sFileNm), 4) 'Extract the file name
sTblNm = Left(sFileNm, 4)
'Use the TransferDatabase option to link the tables from the specified directory
'to your current Access DB
DoCmd.TransferDatabase acLink, "member_combine", sPath, acTable, sTblNm, sTblNm
End If
sFileNm = Dir
Loop
Application.Echo True
End Sub
I have over 100 DB in a file path and I'm trying to create a link from one DB. It will be impractical to go thru the link table wizard so I tried this code below. I'm not recieved an error but it doesn't loop thru the directory or it doesn't create all the link. What is missing?
Thanks
Sub LinkAllTblsinDir()
Dim sTblNm As String
Dim sPath As String
Dim sFileNm As String
sPath = "C:\Users\"
'Turn of the Echo to avoid window repaint/refresh
Application.Echo False
sFileNm = Dir(sPath, vbNormal)
Do While sFileNm <> ""
If Right(sFileNm, 3) = “mdb” Then
'sTblNm = Left(sFileNm, Len(sFileNm), 4) 'Extract the file name
sTblNm = Left(sFileNm, 4)
'Use the TransferDatabase option to link the tables from the specified directory
'to your current Access DB
DoCmd.TransferDatabase acLink, "member_combine", sPath, acTable, sTblNm, sTblNm
End If
sFileNm = Dir
Loop
Application.Echo True
End Sub