2009/07/10

access2007:パスワードロックしたaccdbからリンクテーブル作成

MSDNlibraryみたんだけどエラー出るから直した
Sub CreateLinkedAccessTable(strDBLinkFrom As String, _
                            strDBLinkTo As String, _
                            strLinkTbl As String, _
                            strLinkTblAs As String, _
                            Pswd As String)

Dim catDB As ADOX.Catalog
Dim tblLink As ADOX.Table

 Set catDB = New ADOX.Catalog
 catDB.ActiveConnection = "Provider=Microsoft.ACE.OLEDB.12.0;" & _
                          "Data Source=" & strDBLinkTo & _
                          ";Jet OLEDB:Database Password=" & Pswd & ";"

 Set tblLink = New ADOX.Table
 With tblLink
  .Name = strLinkTblAs
  Set .ParentCatalog = catDB
      .Properties("Jet OLEDB:Create Link") = True
      .Properties("Jet OLEDB:Link Datasource") = strDBLinkFrom
      .Properties("Jet OLEDB:Remote Table Name") = strLinkTbl
      .Properties("Jet OLEDB:Link Provider String") = ";pwd=" & Pswd
  End With

 catDB.Tables.Append tblLink

 Set catDB = Nothing
End Sub

0 件のコメント: