怎樣使用一個(gè)查詢獲得數(shù)據(jù)庫(kù)對(duì)象的名稱

字號(hào):

'功能:獲取access庫(kù)中表的個(gè)數(shù)及表的名稱
    '用ado怎樣實(shí)現(xiàn)
    '工程--->引用--->Microsoft ActiveX Data Object 2.x(版本號(hào))
    '----------------------------------------------------------------------------
    Private Sub Form_Load()
    Dim adoCN As New ADODB.Connection '定義數(shù)據(jù)庫(kù)的連接
    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