怎样判断一个access数据库中某个表是否存在的方法
access数据库创建一个表,Text3是输入的表名称,我想判断数据 库中是否存在此表名称以下代码怎么修改
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
cn.Open "Provider=Microsoft.ace.OLEDB.12.0;Data Source=" & App.Path & "\storage.accdb" & ";Persist Security Info=False"
Set rs = cn.OpenSchema(adSchemaTables)
If rs!TABLE_NAME = Text3.Text Then
MsgBox "存在此表名"
Exit Sub
End If
[解决办法]
读 Scheme 表即可:
Dim cnn1 As ADODB.Connection
Dim rstSchema As ADODB.Recordset
Dim strCnn As String
Set cnn1 = New ADODB.Connection
strCnn = "Provider=Microsoft.ace.OLEDB.12.0;Data Source=" & App.Path & "\storage.accdb" & ";Persist Security Info=False"
cnn1.Open strCnn
Set rstSchema = cnn1.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
cnn1.Close