当前位置:数据库 > Access >>

获取access库中表的个数及表的名称收藏

答案:
'功能:获取access库中表的个数及表的名称
'用ado怎样实现
'工程--->引用--->Microsoft ActiveX Data Object 2.x(版本号)
'----------------------------------------------------------------------------
Private Sub Form_Load()
Dim adoCN   As New ADODB.Connection                '定义数据库的连接
Dim strCnn   As New ADODB.Recordset
Dim rstSchema As New ADODB.Recordset
Dim I As Integer
   str1 = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Northwind.MDB;Persist Security Info=False"
   adoCN.Open str1
        
   Set rstSchema = adoCN.OpenSchema(adSchemaTables)
    
   Do Until rstSchema.EOF
        If rstSchema!TABLE_TYPE = "TABLE" Then
           out = out & "Table  name:  " & _
               rstSchema!TABLE_NAME & vbCr & _
               "Table  type:  " & rstSchema!TABLE_TYPE & vbCr
            I = I + 1
        End If
        rstSchema.MoveNext
   Loop
   MsgBox I
   rstSchema.Close
    
   adoCN.Close
Debug.Print out
End Sub  


方法二:

 

 Access 系统表 MsysObjects 包含了数据库对象列表。尽管未在文档中记载,你仍可通过查询它来获取你想要的。但是默认情况下无法操作系统表,必须手动设定权限收才能查询系统表。
请参考以下动画:如何获取对msysobject的操作权限
http://access911.net/eg/swf/msobject.swf

警告:不要修改任何ACCESS系统表,否则会出现不可意料的情况.

使用下列 SQL 语句来获取你想要的

查询:
SELECT MSysObjects.Name FROM MsysObjects WHERE (Left([Name],1)<>"~") AND (MSysObjects.Type)=5 ORDER BY MSysObjects.Name;


窗体:
SELECT MSysObjects.Name FROM MsysObjects WHERE (Left([Name],1)<>"~") AND (MSysObjects.Type)=-32768 ORDER BY MSysObjects.Name;


表:
SELECT MSysObjects.Name FROM MsysObjects WHERE (Left([Name],1)<>"~") AND (Left$([Name],4) <> "Msys") AND (MSysObjects.Type)=1 ORDER BY MSysObjects.Name;


报表:
SELECT MSysObjects.Name FROM MsysObjects WHERE (Left([Name],1)<>"~") AND (MSysObjects.Type)= -32764 ORDER BY MSysObjects.Name;


模块:
SELECT MSysObjects.Name FROM MsysObjects WHERE (Left([Name],1)<>"~") AND (MSysObjects.Type)= -32761 ORDER BY MSysObjects.Name;


宏:
SELECT MSysObjects.Name FROM MsysObjects WHERE (Left([Name],1)<>"~") AND (MSysObjects.Type)= -32766 ORDER BY MSysObjects.Name;

上一个:备份你的改过后缀名的ACCESS数据库
下一个:Access中查询某个分组中多行字段值的拼接字串的方法

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,