กระทู้เก่าบอร์ด อ.สุภาพ ไชยา
285 1
URL.หัวข้อ /
URL
Changing linked tables to actual tables in code
ถามไว้ที่ http://board.quicktechusa.com/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=1;t=005085
ลองเข้าไปดูโค้ดในการเปลี่ยนตารางที่ลิ้งค์ไว้ ให้เป็นตารางจริงในไฟล์ฐานข้อมูลปัจจุบันครับ
Function GetLinkedPath(strTable As String)
Dim strPath As String
strPath = CurrentDb.TableDefs(strTable).Connect
GetLinkedPath = Mid(strPath, InStr(strPath, "=") + 1)
End Function
Function UnLinks() As Boolean
Dim dbs As DAO.Database
Dim intCount As Integer
Dim tdf As DAO.TableDef
Dim strName As String
Dim strBackEnd As String
' Loop through all tables in the database.
Set dbs = CurrentDb
For intCount = 0 To dbs.TableDefs.Count - 1
Set tdf = dbs.TableDefs(intCount)
' If the table has a connect string, it's a linked table.
If Len(tdf.Connect) > 0 Then
strName = tdf.Name
' Get the BackEnd name.
strBackEnd = GetLinkedPath(tdf.Name)
' Delete the linked table.
DoCmd.DeleteObject acTable, strName
' Import the table back.
DoCmd.TransferDatabase acImport, "Microsoft Access", strBackEnd, acTable, strName, strName
Err = 0
On Error Resume Next
If Err <> 0 Then
UnLinks = False
Exit Function
End If
End If
Next intCount
UnLinks = True ' Unlinking complete.
End Function
ลองเข้าไปดูโค้ดในการเปลี่ยนตารางที่ลิ้งค์ไว้ ให้เป็นตารางจริงในไฟล์ฐานข้อมูลปัจจุบันครับ
Function GetLinkedPath(strTable As String)
Dim strPath As String
strPath = CurrentDb.TableDefs(strTable).Connect
GetLinkedPath = Mid(strPath, InStr(strPath, "=") + 1)
End Function
Function UnLinks() As Boolean
Dim dbs As DAO.Database
Dim intCount As Integer
Dim tdf As DAO.TableDef
Dim strName As String
Dim strBackEnd As String
' Loop through all tables in the database.
Set dbs = CurrentDb
For intCount = 0 To dbs.TableDefs.Count - 1
Set tdf = dbs.TableDefs(intCount)
' If the table has a connect string, it's a linked table.
If Len(tdf.Connect) > 0 Then
strName = tdf.Name
' Get the BackEnd name.
strBackEnd = GetLinkedPath(tdf.Name)
' Delete the linked table.
DoCmd.DeleteObject acTable, strName
' Import the table back.
DoCmd.TransferDatabase acImport, "Microsoft Access", strBackEnd, acTable, strName, strName
Err = 0
On Error Resume Next
If Err <> 0 Then
UnLinks = False
Exit Function
End If
End If
Next intCount
UnLinks = True ' Unlinking complete.
End Function
1 Reply in this Topic. Dispaly 1 pages and you are on page number 1
1 @R06733
Time: 0.1171s