* 업데이트 : - 나는 참조 기능 Relink_CSV :(
을 포함하는 것을 잊었다 네, 그것은 버그를 부를 것이다 마이크로 소프트는 아마 '특성 디자인'이라고 부른다
당신이 발견 한 것처럼.. CSV 파일이 쉼표로 구분 된 경우 코드 솔루션에 관심이있는 경우 CSV 파일을 쉼표로 구분하면
다음 코드 (필요한 경우)를 사용하여 문제를 해결할 수 있습니다. 수정!) 기존 링크 된 csv 파일을 삭제 한 다음 동일한 파일에 링크를 추가합니다. 디버깅을 위해 내 코드는 해당 링크를 삭제하고 다른 폴더에 있지만 동일한 폴더에있는 링크.
csv 형식이 단순하지 않은 경우 저장된 가져 오기 사양을 사용하여 다시 사용할 수있는 다른 솔루션이 있습니다.
Option Explicit
Option Compare Database
Sub Call_Relink()
Dim dbs As DAO.Database
Dim tdf As DAO.TableDef
Dim strTableName As String
Dim strPath As String
Dim strFile As String
Dim iReply As Integer
iReply = MsgBox("WARNING!!!! This code will remove the linked tables 'FileA' and 'FileB'" & vbCrLf & vbCrLf & _
"Click 'Yes' to Continue" & vbCrLf & "Click 'No' to Stop", vbYesNo, "CAUTION!! Will remove linked table(s)")
If iReply <> vbYes Then
Exit Sub
End If
On Error GoTo Error_Trap
Set dbs = CurrentDb
dbs.TableDefs.Delete "FileA" ' For testing; delete table if it already exists
strPath = "C:\Temp\"
strFile = "FileA.csv"
strTableName = "FileA" ' Table name in Access
Relink_CSV strTableName, strPath, strFile ' Call function to link the CSV file
dbs.TableDefs.Refresh ' Refresh TDF's
Debug.Print "Pause here and check file link" ' Put a breakpoint here; pause and look at the table in Access
dbs.TableDefs.Delete "FileA" ' For testing; delete table if it already exists
strPath = "C:\Temp\" ' Path to next csv
strFile = "FileB.csv" ' Name of next csv file
strTableName = "FileA" ' Table name in Access
Relink_CSV strTableName, strPath, strFile ' Call function to link to a different CSV file
dbs.TableDefs.Refresh
Debug.Print "Pause here and check file link" ' Put a breakpoint here; pause and look at the table in Access
My_Exit:
Set dbs = Nothing
Exit Sub
Error_Trap:
Debug.Print Err.Number & vbTab & Err.Description
If Err.Number = 3265 Then ' Item not found in this collection.
' Ignore this error
Resume Next
End If
MsgBox Err.Number & vbTab & Err.Description
Resume My_Exit
Resume
End Sub
Function Relink_CSV(strTableName As String, strPath As String, strFile As String)
' (1) Name of the table in Access
' (2) Path to the file
' (3) File name
On Error GoTo Relink_Err
DoCmd.TransferText acLinkDelim, , strTableName, strPath & strFile, False, ""
Relink_Exit:
Exit Function
Relink_Err:
Debug.Print Err.Number & vbTab & Err.Description
MsgBox Err.Number & vbTab & Err.Description
Resume Relink_Exit
Resume
End Function
다른 이름의 파일 (예 : FileA.csv와 FileB.csv)을 선택하려고하십니까? FileA.csv에 연결 한 다음 Linked Table Manager를 사용하고 FileB.csv에 연결하면 작동하지만 동일한 이전 파일이 유지됩니다. 다른 폴더의 FileA.csv에 다시 연결하면 예가 올바르게 작동합니다. 또한 다음 링크에서 코드를 테스트했는데 삭제/다시 링크 작업을하는 것처럼 보입니다. http://www.tek-tips.com/viewthread.cfm?qid=865710 –
정확합니다. 그러나 단순히 현재 경로의 하위 폴더를 사용할 수 없습니다. 나는 완전히 새로운 폴더를 골라야했다. 그것은 내가 그것을 시도 할 때 그것이 나를 위해 효과가 없었던 이유의 일부였다. 이상한 버그와 오랜 시간 전에 Microsoft가 해결해야했던 버그. 답변으로 의견을 게시하여 해결책으로 확인해주십시오! 감사합니다 – rohrl77