Data import/linking problem

BubBob

Registered User.
Local time
Today, 22:09
Joined
May 20, 2003
Messages
10
I have a folder that has database files that are named by date (evt3010.mdb) All of them contain only one table EventTable. How can i automatically import or link these to my database and rename tables preferably by date or filename (or something else). I'm stuck with this issue, any ideas?
 
I wrote something similiar to what you are asking... Make a table called tblDefs. Make 3 field named, TblNames, DBName and NewtblName. This code will loop throught this table and link whatever tables you entered in tblDefs.


Public Function ReLink()
Dim strFolderName As String
Dim rst As Recordset
Dim dbsTemp As Database
Dim tdfLinked As TableDef
Dim strConnect As String
Dim strSourceTable As String
Set dbsTemp = CurrentDb

'Set strFolderName to be whatever folder your DB's are in
strFolderName = "C:/DBFolder"

Set rst = dbsTemp.OpenRecordset("tblDefs", dbOpenDynaset)
rst.MoveFirst
Do While rst.EOF = False
strConnect = strFolderName & "\" & rst("DBName")
strSourceTable = rst("TblNames")
Set tdfLinked = dbsTemp.CreateTableDef(strSourceTable)
tdfLinked.Connect = ";DATABASE=" & strConnect
tdfLinked.SourceTableName = strSourceTable

dbsTemp.TableDefs.Append tdfLinked
'This line will rename the newly linked table to whatever you want.
DoCmd.Rename rst("NewtblName"), acTable, rst("tblNames")
rst.MoveNext
Loop

RefreshDatabaseWindow
strFolderName & "'" & ";"

End Function


Hope this helps
 

Users who are viewing this thread

Back
Top Bottom