问题:
只用ado列出所有的表
回答:
Public Function listalltable()
Dim rstSchema As ADODB.Recordset
Dim strCnn As String
Set cnn2 = CurrentProject.Connection
Set rstSchema = cnn2.OpenSchema(adSchemaTables)
Do Until rstSchema.EOF
Debug.Print "Table name: " & _
rstSchema!TABLE_NAME & vbCr & _
"Table type: " & rstSchema!TABLE_TYPE & vbCr
rstSchema.MoveNext
Loop
rstSchema.Close
cnn2.Close
End Function
大家不要局限与只使用 OpenSchema 来列举表,OpenSchema 还有很多参数,几乎可以列举数据库的所有对象,以下再演示一个列举 VIEW 的例子,还有其他很多参数,大家还是多看看帮助吧。
Function list_view()
Dim Rs As ADODB.Recordset
Dim Conn As ADODB.Connection
Set Conn = CurrentProject.Connection
Set Rs = Conn.OpenSchema(adSchemaViews)
Dim i As Long
Do Until Rs.EOF
For i = 0 To Rs.Fields.Count - 1
Debug.Print Rs(i).Name & " -> " & Rs(i).Value
Next i
Rs.MoveNext
Loop
End Function