office交流网--QQ交流群号

Access培训群:792054000         Excel免费交流群群:686050929          Outlook交流群:221378704    

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

Access利用ADOX获取Access数据库字段的所有属性

2017-08-03 06:41:00
zstmtony
原创
5493
利用ADOX获取Access数据库字段的所有属性


可以读到一个Access数据库中所有表与字段的信息


'获取Access数据库所有字段的所有属性  本程序需要先引用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交流网\AccessCn.mdb"
If Dir(strDataBase) = "" Then
MsgBox "数据库:" & strDataBase & "不存在!"
Exit Sub
End If
strPasword= "" '数据库密码
strTableName = "我的数据表"

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交流网"
End Sub

程序中的数据库名,密码与数据表名,请按自己的需要修改


字段的相关属性如下面内容:

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 有效性规则
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 超链接型
分享