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

发表于:2007-05-25来源:作者:点击数: 标签:个数收藏Access中表获取
'功能:获取access库中表的个数及表的名称 '用ado怎样实现 '工程---引用---Microsoft ActiveX Data Object 2.x(版本号) '---------------------------------------------------------------------------- Private Sub Form_Load() Dim adoCN As New ADODB.

'功能:获取aclearcase/" target="_blank" >ccess库中表的个数及表的名称
'用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://image.chinaitpower.com/flash/20041016/10484.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;

原文转自:http://www.ltesting.net