2017-05-22 3 views
0

CSV 파일에 연결된 테이블이있는 MS Access 2010 데이터베이스가 있습니다. inbuilt Access "Linked Table Manager"를 사용하여 CSV 파일 위치를 올리는 기능이 작동하지 않습니다.MS Access 연결된 테이블 관리자가 새 데이터 소스를 업데이트하지 않습니다.

내가 업데이트 할 파일을 확인하고 "항상 새 위치를 묻습니다"를 선택하고 새 파일을 선택하십시오. 업데이트가 성공했다는 메시지가 나타 났지만 체크 할 때 테이블은 여전히 ​​이전 파일에 연결되어 있습니다.

이것은 MS Access 버그입니까? 그렇다면 가장 효율적인 해결 방법은 무엇입니까?

이전 테이블을 삭제하고 동일한 사양의 새 테이블을 수동으로 다시 만들었습니다.

+1

다른 이름의 파일 (예 : FileA.csv와 FileB.csv)을 선택하려고하십니까? FileA.csv에 연결 한 다음 Linked Table Manager를 사용하고 FileB.csv에 연결하면 작동하지만 동일한 이전 파일이 유지됩니다. 다른 폴더의 FileA.csv에 다시 연결하면 예가 올바르게 작동합니다. 또한 다음 링크에서 코드를 테스트했는데 삭제/다시 링크 작업을하는 것처럼 보입니다. http://www.tek-tips.com/viewthread.cfm?qid=865710 –

+0

정확합니다. 그러나 단순히 현재 경로의 하위 폴더를 사용할 수 없습니다. 나는 완전히 새로운 폴더를 골라야했다. 그것은 내가 그것을 시도 할 때 그것이 나를 위해 효과가 없었던 이유의 일부였다. 이상한 버그와 오랜 시간 전에 Microsoft가 해결해야했던 버그. 답변으로 의견을 게시하여 해결책으로 확인해주십시오! 감사합니다 – rohrl77

답변

1

* 업데이트 : - 나는 참조 기능 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 
+0

'Relink_CSV' 코드없이 완료하지 않았습니다 –

+0

@CPerkins 잡아 주셔서 감사합니다! 잃어버린 기능을 추가했습니다. –