|
|
Подключение всех таблиц внешней БД (DAO) v014
Public Function LinkAllTables_MSADB_DAO(sSrcDBPath As String, Optional sLocalPrefix$ = "") As Long
Dim dbSrc As DAO.Database, tdfSrc As DAO.TableDef
Dim dbLocal As DAO.Database, tdfLocal As DAO.TableDef
Dim sSrcDBConnectionStr$, sSrcTableName$, sLocalTableName$
Dim iConut%
On Error GoTo LinkAllTables_MSADB_DAO_Err
Set dbLocal = CurrentDb
Set dbSrc = DBEngine.OpenDatabase(sSrcDBPath)
sSrcDBConnectionStr = ";DATABASE=" & sSrcDBPath
For Each tdfSrc In dbSrc.TableDefs
If tdfSrc.Attributes = 0 Then
sSrcTableName = tdfSrc.Name
sLocalTableName = sLocalPrefix & sSrcTableName
If DCount("*", "MSysObjects", "[Name] = '" & sLocalTableName & "' AND Type=6") > 0 Then
Set tdfLocal = dbLocal.TableDefs(sLocalTableName)
If Not tdfLocal.Connect = sSrcDBConnectionStr Then
tdfLocal.Connect = sSrcDBConnectionStr
tdfLocal.RefreshLink
End If
Else
Set tdfLocal = dbLocal.CreateTableDef(sLocalTableName)
tdfLocal.Connect = sSrcDBConnectionStr
tdfLocal.SourceTableName = sSrcTableName
CurrentDb.TableDefs.Append tdfLocal
End If
iConut = iConut + 1
End If
Next tdfSrc
If iConut > 0 Then _
MsgBox "Все таблицы файла:" & vbCrLf & sSrcDBPath & vbCrLf & _
"Подключены в кол-ве: " & iConut & "шт.", vbInformation, "Подключение Таблиц"
LinkAllTables_MSADB_DAO_Bye:
On Error Resume Next
Set tdfSrc = Nothing: dbSrc.Close: Set dbSrc = Nothing
Set tdfLocal = Nothing: dbLocal.Close: Set dbLocal = Nothing
Err.Clear
Exit Function
LinkAllTables_MSADB_DAO_Err:
LinkAllTables_MSADB_DAO = Err.Number
Debug.Print "LinkAllTables_MSADB_DAO - Err on sSrcTableName:" & sSrcTableName
Resume LinkAllTables_MSADB_DAO_Bye
End Function
|
|