How to determine if a known table exists in the library today, to help him solve this problem, the code for the usual reference DAO to do a module:
Function fExistTable(strTableName As String) As Integer
Dim db As Database
Dim i As Integer
Set db = DBEngine.Workspaces(0).Databases(0)
fExistTable = False
db.TableDefs.Refresh
For i = 0 To db.TableDefs.Count - 1
If strTableName = db.TableDefs(i).Name Then
'Table Exists
fExistTable = True
Exit For
End If
Next i
Set db = Nothing
End Function
Private Sub 命令0_Click()
fExistTable
End Sub
A ' parameter not selectable ' error occurred with this event. After careful study, we found that fexisttable is missing the parameter, that is, the table name is not reflected in the code.
Modified to:
Private Sub 命令0_Click()
fExistTable(”需判断的已知表名”)
End Sub
End Sub no longer complains. Careful analysis, in fact, with "known table name" through DAO to determine whether there is a database, if the value of fexisttable is true is there, otherwise it does not exist.
Solve the problem, think of Access database also has system tables, stored with object name, can make a query to determine?
Verified by:
SELECT Count(*) AS Qty
FROM MSysObjects
WHERE (((MSysObjects.Name) Like "需判断的已知表名"));
can achieve requirements. If qty>0, it means that the table already exists, otherwise it does not exist.