昨夜遅くまでかかり、Microsoft社のWebページDAO から ADO への移植4を参考にやっとこ出来たモジュール。実際に走らせて動作を確認したがDAOの方がよっぽど早い。DAOでも、ネットワーク先のテーブルにリンクすると遅くなるが、その時の速さと同じと感じた。将来を考えるとADOで開発を進めるべきであろうが、私に将来はあるのであろうか...m(_ _)m
Public Function Connect_Table(Optional argIsReset As Boolean = True) As Boolean On Error GoTo Err_Connect_Table Dim mbTitle As String Dim CNN As New ADODB.Connection Dim RST As New ADODB.Recordset Dim CAT As New ADOX.Catalog Dim TBL As New ADOX.Table : :(省略) : 'リンクする。 openRST = "Select * from tblConnectTable Where (([ConnectID]=2) and ([noConnect] = False))" _ & " Order by [cnnMDB],[myTable]" RST.Open openRST, CNN, adOpenForwardOnly Set CAT = New ADOX.Catalog Do Until RST.EOF strFullPath = Nz(Get_PathName(Trim(RST!cnnPath)) & Trim(RST!cnnMDB)) strMyTable = Nz(Trim(RST!myTable)) strSrcTable = Nz(Trim(RST!srcTable)) If strSrcTable = "" Then strSrcTable = strMyTable INTAns = Delete_aObject(strMyTable, "T") 'Open the catalog CAT.ActiveConnection = CurrentProject.Connection 'Set the name and target catalog for the table TBL.Name = strSrcTable Set TBL.ParentCatalog = CAT 'Set the properties to create the link TBL.Properties("Jet OLEDB:Create Link") = True TBL.Properties("Jet OLEDB:Link Datasource") = strFullPath TBL.Properties("Jet OLEDB:Link Provider String") = ";pwd=password" TBL.Properties("Jet OLEDB:Remote Table Name") = strSrcTable 'Append the table to the collection CAT.Tables.Append TBL DoEvents RST.MoveNext Loop RST.Close : :(省略) : End Function
Webページと大きく異なるところは、
"CAT.ActiveConnection = CurrentProject.Connection"
ま、やってみたら出来たので、文法上は間違いのであろう と思われる。