程式設計管理(新增、刪除、重新整理) Access 連結表資訊 (轉)
'首先 , 作如下測試工作:
'新建空白 Access (.m) ,
'並新增若干型別連結表:
'se 5 (*.dbf)、
' (*.xls)、
'Microsoft Access (*.mdb;*.mda;*.mde) 等,
'然後再編寫如下 :
'、等程式同理也可:
'引用 Microsoft Data s 2.x Library
'引用 Microsoft ADO Ext. 2.x for DDL and Security
': Form1、Command1、Command2、Command3
Private Sub Command1_Click() '測試連結表資訊
Dim adoConnection As New ADODB.Connection
adoConnection.Open "Provr=Microsoft.Jet.OLEDB.4.0;Data =E:LnkTbls.mdb;Persist Security Info=False;Jet OLEDB:Database Pass=123"
Dim adoCatalog As New ADOX.Catalog
Set adoCatalog.ActiveConnection = adoConnection
Dim adoTable As New ADOX.Table
Set adoTable.ParentCatalog = adoCatalog
Dim i As Integer
For Each adoTable In adoCatalog.Tables
If adoTable.Type = "LINK" Then
De.Print adoTable.Name
For i = 0 To adoTable.Properties.Count - 1
Debug.Print " " & adoTable.Properties.Item(i).Name & ": " & adoTable.Properties.Item(i).Value
Next i
Debug.Print VBA.vbCrLf
End If
Next adoTable
End Sub
'新增連結表
Private Sub Command2_Click()
Dim adoConnection As New ADODB.Connection
adoConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:LnkTbls.mdb;Persist Security Info=False;Jet OLEDB:Database Password=123"
Dim adoCatalog As New ADOX.Catalog
Dim adoTable As New ADOX.Table
'Access
Set adoCatalog.ActiveConnection = adoConnection
Set adoTable.ParentCatalog = adoCatalog
adoTable.Properties.Item("Jet OLEDB:Link Datasource").Value = "e:nwind2kpwd.mdb"
adoTable.Properties.Item("Jet OLEDB:Remote Table Name").Value = "產品"
adoTable.Properties.Item("Jet OLEDB:Create Link").Value = True
adoTable.Properties.Item("Jet OLEDB:Link Provider String").Value = "MS Access;Pwd=456"
adoTable.Name = "Access"
adoCatalog.Tables.Append adoTable
adoConnection.Close
'dBase
adoConnection.Open
Set adoCatalog.ActiveConnection = adoConnection
Set adoTable.ParentCatalog = adoCatalog
adoTable.Properties.Item("Jet OLEDB:Link Datasource").Value = "E:BorlandSharedData"
adoTable.Properties.Item("Jet OLEDB:Remote Table Name").Value = "animals#dbf"
adoTable.Properties.Item("Jet OLEDB:Create Link").Value = True
adoTable.Properties.Item("Jet OLEDB:Link Provider String").Value = "dBase 5.0"
adoTable.Name = "dBase5"
adoCatalog.Tables.Append adoTable
adoConnection.Close
'Excel
adoConnection.Open
Set adoCatalog.ActiveConnection = adoConnection
Set adoTable.ParentCatalog = adoCatalog
adoTable.Properties.Item("Jet OLEDB:Link Datasource").Value = "E:Book97.xls"
adoTable.Properties.Item("Jet OLEDB:Remote Table Name").Value = "Sheet1$"
adoTable.Properties.Item("Jet OLEDB:Create Link").Value = True
adoTable.Properties.Item("Jet OLEDB:Link Provider String").Value = "Excel 5.0;HDR=NO;IMEX=2"
adoTable.Name = "Excel"
adoCatalog.Tables.Append adoTable
adoConnection.Close
'...
End Sub
'程式設計刪除連結表
Private Sub Command3_Click()
Dim adoConnection As New ADODB.Connection
adoConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:LnkTbls.mdb;Persist Security Info=False;Jet OLEDB:Database Password=123"
Dim adoCatalog As New ADOX.Catalog
Set adoCatalog.ActiveConnection = adoConnection
Dim j As Integer
Dim i As Integer
For i = adoCatalog.Tables.Count To 1 Step -1
If adoCatalog.Tables.Item(i - 1).Type = "LINK" Then
Debug.Print adoCatalog.Tables.Item(i - 1).Name
For j = 0 To adoCatalog.Tables.Item(i - 1).Properties.Count - 1
Debug.Print " " & adoCatalog.Tables.Item(i - 1).Properties.Item(j).Name & ": " & adoCatalog.Tables.Item(i - 1).Properties.Item(j).Value
Next j
Debug.Print VBA.vbCrLf
If VBA.MsgBox("Delete link table [" & adoCatalog.Tables.Item(i - 1).Name & "]?", vbYesNo) Then
adoCatalog.Tables.Delete adoCatalog.Tables.Item(i - 1).Name
End If
End If
Next i
End Sub
Private Sub Command4_Click()
Dim adoConnection As New ADODB.Connection
adoConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:LnkTbls.mdb;Persist Security Info=False;Jet OLEDB:Database Password=123"
Dim adoCatalog As New ADOX.Catalog
Set adoCatalog.ActiveConnection = adoConnection
adoCatalog.Tables.Item("Excel").Properties.Item("Jet OLEDB:Link Provider String").Value = "Excel 5.0;HDR=yes;IMEX=2"
End Sub
Private Sub Form_Load()
Command1.Caption = "連結表資訊"
Command2.Caption = "新增連結表"
Command3.Caption = "刪除連結表"
Command4.Caption = "重新整理連結表"
End Sub
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-992435/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Java 操作PDF中的超連結——新增、更新、刪除超連結Java
- 軟連結刪除
- 巧用FC5的“新增/刪除程式”(轉)
- 巧用Fedora Core 5的“新增/刪除程式”(轉)
- javascript新增刪除cookie程式碼JavaScriptCookie
- 學生資訊管理系統(二)刪除資訊
- 理解Window的新增,刪除,重新整理內部機制
- js操作 新增刪除table行,並進行重新整理JS
- mysql連結很多,批量刪除異常程式processlistMySql
- ASM的管理----刪除和新增磁碟組ASM
- 新增刪除程式打不開怎麼辦 新增刪除程式報錯解決辦法
- 刪除windows預設開啟的管理共享(轉)Windows
- ava 新增、刪除Excel表單控制元件Excel控制元件
- win10新增或刪除程式在哪 win10系統怎麼開啟新增或刪除程式Win10
- 刪除 Windows 98 解除安裝資訊(轉)Windows
- informix新增刪除chunkORM
- 部落格連結—程式設計程式設計
- 程式設計和除錯中的幾點總結 (轉)程式設計除錯
- 請求版主刪除本人 facebook 連結和 ins 的連結
- MongoDB 刪除,新增副本集,並修改副本集IP等資訊MongoDB
- React實現表單資料的新增與刪除React
- networkx基礎用法:新增節點、新增邊、刪除節點、刪除邊、計算度、賦權重
- 轉:Oracle RAC 新增和刪除OCR(10g)Oracle
- 軟連線與硬連結的區別,以及如何刪除軟連結
- 雙向連結串列————查詢、刪除、插入結點
- css刪除超連結底部的橫線CSS
- 刪除陣列中的元素(連結串列)陣列
- oracle表結構設計轉摘Oracle
- jQuery 新增和刪除classjQuery
- 紅黑樹新增刪除
- Cookie 的新增與刪除Cookie
- js新增刪除文字框JS
- Solr 刪除和新增 indexSolrIndex
- 新增/刪除約束(Oracle)Oracle
- swap分割槽新增刪除
- ASP.NET新增、修改、刪除web.config配置資訊ASP.NETWeb
- 表管理之二:表資料的插入修改與刪除
- 程式設計方法論/架構設計/模式相關轉載連結彙總程式設計架構模式