2016-08-15 2 views
0

프런트 엔드와 백엔드 모두가 accdb 파일 인 분할 데이터베이스가 있습니다. 내 테이블 중 하나가 AppendOnly = Yes 속성을 사용하기 때문에 백엔드를 이동할 때 링크 테이블 관리자 또는 refreshlink 속성을 사용할 수 없습니다. 내 IT 부서가 서버를 개편하기를 좋아하기 때문에 백엔드가 때때로 이동합니다.VBA를 사용하여 Access DB간에 테이블을 연결하려고합니다. ISAM을 찾을 수 없습니다 오류가 발생했습니다

내 솔루션은 백엔드 위치를 묻는 기능을 작성하고 현재 연결된 모든 테이블을 삭제 한 다음 모든 백엔드 테이블을 반복하고 프론트 엔드에 연결합니다. 이 마지막 부분에서 런타임 오류 3170 적절한 ISAM을 찾을 수 없습니다 나타납니다. 나는 이유를 모른다.

코드는 다음과 같습니다 :

Public Function MoveDB() 

'this function will replace the linked table manager. It will open a file select dialog box to allow the user to pick the new location of the DB backend. 
'It will then break all the current links and then recreate them. We need to do this vice use the relink function because the cases table uses AutoAppend which stores old path data 
' and breaks the relink function which is why linked table manager does not work. 

' FileDialog Requires a reference to Microsoft Office 11.0 Object Library. 

'variables to get the database path 
Dim fDialog As Office.FileDialog 
Dim varFile As Variant 
Dim DriveLetter As String 
Dim NetworkPath As String 
Dim DrivePath As String 
Dim SubPath As String 


'variables to link the database 
Dim db As DAO.Database 
Dim BEdb As DAO.Database 
Dim oldtdf As DAO.TableDef 
Dim tblName As String 
Dim newtdf As DAO.TableDef 
Dim BEtdf As DAO.TableDef 


Set db = CurrentDb() 

' Set up the File Dialog. 
Set fDialog = Application.FileDialog(msoFileDialogFilePicker) 
With fDialog 

    ' Do not Allow user to make multiple selections in dialog box 
    .AllowMultiSelect = False 

    'set the default folder that is opened 
    .InitialFileName = CurrentProject.Path & "\BE" 

    ' Set the title of the dialog box. 
    .Title = "Please select the Database Backend" 

    ' Clear out the current filters, and add our own. 
    .Filters.Clear 
    .Filters.Add "Access Databases", "*.accdb" 

    ' Show the dialog box. If the .Show method returns True, the 
    ' user picked a file. If the .Show method returns 
    ' False, the user clicked Cancel. 
    If .Show = True Then 

'We need to determine the full network path (including server name) to the DB backend. The reason is that different users may have the share drive mapped with different letters. 
'If the backend is mapped using the drive letter of the user moving the DB then other users may not have a valid path. The full network path is universal 


'Get the mapped drive letter from the path of the selected DB file 
    DriveLetter = Left$(Trim(fDialog.SelectedItems(1)), 2) 
'Get the path of the selected DB file minus the drive letter 
    SubPath = Mid$(Trim(fDialog.SelectedItems(1)), 3) 
'Get the full network path of the mapped drive letter 
    DrivePath = GETNETWORKPATH(DriveLetter) 
'Combine the drive path and the sub path to get the full path to the selected DB file 
    NetworkPath = DrivePath & SubPath 
    'MsgBox (NetworkPath) 
    Else 
    MsgBox "You clicked Cancel in the file dialog box." 
    End If 
End With 
    'Now we need to delete all the linked tables 

For Each oldtdf In db.TableDefs 
    With oldtdf 
     If oldtdf.Attributes And dbAttachedODBC Or oldtdf.Attributes And dbAttachedTable Then 
     'this is a linked table 
      tblName = .Name 
      DoCmd.DeleteObject acTable, tblName 
     End If 
    End With 
Next oldtdf 
tblName = "" 


'Now we link all the tables from the backend to the front end 
Set BEdb = OpenDatabase(NetworkPath) 
For Each BEtdf In BEdb.TableDefs 
    tblName = BEtdf.Name 
    If Left(tblName, 4) <> "~TMP" Then 
     Set newtdf = db.CreateTableDef(strTable) 
     newtdf.Connect = "Database = " & NetworkPath 
     newtdf.SourceTableName = tblName 
     newtdf.Name = tblName 
    db.TableDefs.Append newtdf 
    End If 
Next BEtdf 

End Function 

오류는

db.TableDefs.Append newtdf 

라인에서 발생합니다. 이 코드를 작동 시키거나 AppendOnly=Yes 속성을 사용할 때 링크를 새로 고치는 것을 방지하는 알려진 버그를 해결할 방법을 찾고 있습니다.

미리 도움을 청하십시오.

+0

이이 유용 할 수있다 : 내가 일하고 https://support.microsoft.com/en-us/kb/209805 – cyboashu

+0

코드 개발에 대한 내 바탕 화면에 현재이다. 결과는 다음과 같습니다. Database = \ Users \ [My UserName] \ Desktop \ Database 프로젝트 파일 \ BE \ ACCLOGWINGSAU_be.accdb –

+0

winghei가 문제를 발견했습니다. 그러나 당신이 예견했듯이 나는 존재하지 않는 시스템 테이블을 연결하려고합니다. 테이블 이름을 삭제하기 전에 배열에 테이블 이름을 저장하여 수정하고 필요한 특정 테이블 만 링크 할 수 있도록 링크를 만들 때 루프를 반복합니다. 도와 주셔서 감사합니다. –

답변

1

나는 그냥 여분의 공백

또는
newtdf.Connect = ";Database=" & NetworkPath 
+0

나는 그것을 시험해 보았다. 세미콜론을 추가하면 잘못된 인수 오류가 발생합니다. 그러나 답장을 보내 주셔서 감사합니다. –

+0

공백을 제거하십시오 "; Databases ="&. 그것은 공백이있을 때 당신이 가진 동일한 오류가있어 이후 괜찮을 것입니다 – winghei

+1

그게 효과가있다. 고마워요 –

0

, 당신은 그들이 직접 응용 프로그램의 사용 사이가 없기 때문에는 MSys 테이블을 떠나 DoCmd.TransferDatabase 방법을 사용하고 확신 할 수있는 문자열에 세미콜론을 누락 제거 생각 분할 파일 :

If Left(tblName, 4) <> "~TMP" And Left(tblName, 4) <> "MSys" Then 
    DoCmd.TransferDatabase acLink, "Microsoft Access", NetworkPath, _ 
          acTable, tblName, tblName, False 
End If 
+0

좋은 팁. 감사 –

관련 문제