Is there a simple way in VBA to tell if a table you're about to create already exists? The only thing I know to do right now is look through all the table defs to see if the name is there. Is there a simpler, quicker way? Thanks.
Function DoesTableExist() As Boolean
Dim y As TableDef
On Error Resume Next
Set y = CurrentDb.TableDefs("table2"
If Err.Number = 0 Then DoesTableExist = True
End Function
The key here is the "On Error Resume Next". If the table (or open form or whatever) does not exist then an error occurs. By putting the checking process inside a function readability of your code is improved and reduces the chance that the "on error" will accidently foul up your other error handling routines. (The "On error resume next" applies only inside of the function.)
Function DoesTableExist(MyTable as String) As Boolean
Dim y As TableDef
On Error Resume Next
Set y = CurrentDb.TableDefs(MyTable)
If Err.Number = 0 Then DoesTableExist = True
End Function
MichaelRed
mred@duvallgroup.com
There is never time to do it right but there is always time to do it over
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.