I had to check whether a specific table is already available before creating it through Access VBA script. This is very frequent. This code helped me.
Public Function ifTableExists(tablename As String) As Boolean
ifTableExists = False
If DCount("[Name]", "MSysObjects", "[Name] = '" & tablename & "'") = 1 Then
ifTableExists = True
Else
ifTableExists = False
End If
End Function
After creating above UserDefined Function it can be used asifTableExists = False
If DCount("[Name]", "MSysObjects", "[Name] = '" & tablename & "'") = 1 Then
ifTableExists = True
Else
ifTableExists = False
End If
End Function
If ifTableExists("MyTable") Then db.Execute "DROP Table MyTable"
No comments:
Post a Comment