office交流網(wǎng)--QQ交流群號及微信交流群

Access培訓群:792054000         Excel免費交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

微信交流群(請用微信掃碼)

        

Access利用ADOX獲取Access數(shù)據(jù)庫字段的所有屬性

2017-08-03 06:41:00
zstmtony
原創(chuàng)
6014
利用ADOX獲取Access數(shù)據(jù)庫字段的所有屬性


可以讀到一個Access數(shù)據(jù)庫中所有表與字段的信息


'獲取Access數(shù)據(jù)庫所有字段的所有屬性  本程序需要先引用Microsoft ADO Ext(ADOX)
Public Sub GetAllFldInfo()

Dim adoCat As ADOX.Catalog
Dim adoTab As ADOX.Table
Dim adoCol As ADOX.Column
Dim adoPro As ADOX.Property

Dim strDataBaseAs String, strPaswordAs String, strTableName As String

strDataBase= "D:\Access交流網(wǎng)\AccessCn.mdb"
If Dir(strDataBase) = "" Then
MsgBox "數(shù)據(jù)庫:" & strDataBase & "不存在!"
Exit Sub
End If
strPasword= "" '數(shù)據(jù)庫密碼
strTableName = "我的數(shù)據(jù)表"

Set adoCat = New ADOX.Catalog
adoCat.ActiveConnection = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & strDataBase& ";Jet OLEDB:Database Password=" & strPasword

Set adoTab = New ADOX.Table
Set adoTab = adoCat.Tables(strTableName)

For Each adoCol In adoTab.Columns
Debug.Print adoCol.Name
Debug.Print  adoCol.Type
For Each adoPro In adoCol.Properties
Debug.Print adoPro.Name
Debug.Print adoPro.Value

Next
Next

MsgBox "讀取字段信息完畢!", , "Access交流網(wǎng)"
End Sub

程序中的數(shù)據(jù)庫名,密碼與數(shù)據(jù)表名,請按自己的需要修改


字段的相關(guān)屬性如下面內(nèi)容:

0 Autoincrement 自動編號
1 Default 默認值
2 Description
3 Nullable 必填字段
4 Fixed Length
5 Seed
6 Increment
7 Jet OLEDB:Column Validation Text 有效性文本
8 Jet OLEDB:Column Validation Rule 有效性規(guī)則
9 Jet OLEDB:IISAM Not Last Column
10 Jet OLEDB:AutoGenerate
11 Jet OLEDB:One BLOB per Page
12 Jet OLEDB:Compressed UNICODE Strings
13 Jet OLEDB:Allow Zero Length 允許空字符串
14 Jet OLEDB:Hyperlink 超鏈接型
分享
文章分類
聯(lián)系我們
聯(lián)系人: 王先生
Email: 18449932@qq.com
QQ: 18449932
微博: officecn01
移動訪問