怎样判断一个access数据库中某个表是否存在的方法
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)
Do Until rs.EOF
If rs!TABLE_NAME = Text3.Text Then
MsgBox "存在此表名"
Else
Call db.Execute("select * into " & Text3.Text & " From [Sheet1$] In '" & sPath & "' 'excel 8.0;'")
MsgBox "导出成功", vbOKOnly, "提示"
db.Close
Set db = Nothing
Exit Do
End If
rs.MoveNext
Loop
改了,可是为什么不执行Else后面的语句呢?
[解决办法]
If rs!TABLE_NAME <> Text3.Text Then
Dim db1 As New ADODB.Connection
db1.Open "Provider=Microsoft.ace.OLEDB.12.0;Data Source=" & App.Path & "\storage.accdb" & ";Persist Security Info=False"
Call db1.Execute("select * into " & Text3.Text & " From [Sheet1$] In '" & sPath & "' 'excel 8.0;'")
db1.Close
MsgBox "导出成功", vbOKOnly, "提示"
Set db = Nothing
End If
Do Until rs.EOF
If rs!TABLE_NAME = Text3.Text Then
MsgBox "存在此表名"
Exit Do
End If
rs.MoveNext
Loop