กระทู้เก่าบอร์ด อ.สุภาพ ไชยา
403 1
URL.หัวข้อ /
URL
How to link DBF files to Access automatically?
ถามไว้ที่ http://www.utteraccess.com/forums/showflat.php?Cat=&Board=access_97&Number=180155&page=0&view=collapsed&sb=5&o=7&fpart=1
เขาต้องการที่จะ Link ไฟล์ dbf จำนวนเป็น 100 ไฟล์เข้า Access
ผมแนะนำโค้ดเขาไปดังนี้ครับ
Private Sub LinkDBFNow()
Dim objFS As Object, objFolder As Object
Dim objFiles As Object, objF1 As Object
Dim strFill As String, strFolderPath As String
strFolderPath = CurrentPath
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFS.GetFolder(strFolderPath)
Set objFiles = objFolder.files
For Each objF1 In objFiles
' Loop thru all files in the CurrentPath folder for *.dbf extension.
' If any, link the file to current db.
If Right(objF1.Name, 3) = "dbf" Then
LinkAllDBF objF1.Name
End If
Next
Set objF1 = Nothing
Set objFiles = Nothing
Set objFolder = Nothing
Set objFS = Nothing
End Sub
Function LinkAllDBF(strFileName As String)
Dim dbs As Database
Dim tdf As TableDef
Dim rstSales As Recordset
' Open the Microsoft Access database.
Set dbs = CurrentDb
' Create a TableDef object based on the dbf file name.
Set tdf = dbs.CreateTableDef("Linked_DBF_" & Left(strFileName, Len(strFileName) - 4))
' Set the connection string to specify the source database type and the
' path to the dBase file that contains the data you want to link.
tdf.Connect = "dBase IV;DATABASE=" & CurrentPath & ";"
' Set the Source dBase file you want to access. Just leave the extension, dbf, out.
tdf.SourceTableName = strFileName ' dBase file name.
' Append the TableDef object to the TableDefs collection to create a link.
dbs.TableDefs.Append tdf
dbs.Close
Set dbs = Nothing
End Function
Function CurrentPath() As String
Dim strPath As String
strPath = CurrentDb.Name
CurrentPath = Left(strPath, Len(strPath) - Len(Dir(strPath)))
End Function *** Edited by Supap Chaiya *** 26/4/2546 13:55:05
เขาต้องการที่จะ Link ไฟล์ dbf จำนวนเป็น 100 ไฟล์เข้า Access
ผมแนะนำโค้ดเขาไปดังนี้ครับ
Private Sub LinkDBFNow()
Dim objFS As Object, objFolder As Object
Dim objFiles As Object, objF1 As Object
Dim strFill As String, strFolderPath As String
strFolderPath = CurrentPath
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFS.GetFolder(strFolderPath)
Set objFiles = objFolder.files
For Each objF1 In objFiles
' Loop thru all files in the CurrentPath folder for *.dbf extension.
' If any, link the file to current db.
If Right(objF1.Name, 3) = "dbf" Then
LinkAllDBF objF1.Name
End If
Next
Set objF1 = Nothing
Set objFiles = Nothing
Set objFolder = Nothing
Set objFS = Nothing
End Sub
Function LinkAllDBF(strFileName As String)
Dim dbs As Database
Dim tdf As TableDef
Dim rstSales As Recordset
' Open the Microsoft Access database.
Set dbs = CurrentDb
' Create a TableDef object based on the dbf file name.
Set tdf = dbs.CreateTableDef("Linked_DBF_" & Left(strFileName, Len(strFileName) - 4))
' Set the connection string to specify the source database type and the
' path to the dBase file that contains the data you want to link.
tdf.Connect = "dBase IV;DATABASE=" & CurrentPath & ";"
' Set the Source dBase file you want to access. Just leave the extension, dbf, out.
tdf.SourceTableName = strFileName ' dBase file name.
' Append the TableDef object to the TableDefs collection to create a link.
dbs.TableDefs.Append tdf
dbs.Close
Set dbs = Nothing
End Function
Function CurrentPath() As String
Dim strPath As String
strPath = CurrentDb.Name
CurrentPath = Left(strPath, Len(strPath) - Len(Dir(strPath)))
End Function *** Edited by Supap Chaiya *** 26/4/2546 13:55:05
1 Reply in this Topic. Dispaly 1 pages and you are on page number 1
Time: 0.1108s
ให้ดูที่กระทู้ http://www.utteraccess.com/forums/showflat.php?Cat=&Board=access_2000&Number=217206&Forum=All_Forums&Words=TimK&Match=Username&Searchpage=0&Limit=25&Old=allposts&Main=217195&Search=true#Post217206 นะครับ