G
Guest
In Access 2003, 2000 format, I'm trying to see if a table exists. I've copied
different code from other postings and have the same problem for most. When a
table does not exits I get the error: Run-time error '3265' Item not found in
this collection. on this line - Set tdefTable = dbDatabase(strTableName)
Here is the last code I tried. I thought the purpose of 'On Error Resume
Next' was to move to the next line of code where in this case function should
return 'false'.
What am I missing? Thanks for suggestions.
Function TableExists(strTableName As String) As Integer
' Checks for the existance of a specific table
'Added the tabledefs.refresh as tables just added in this session weren't
' being picked up.
Dim dbDatabase As Database, tdefTable As TableDef
On Error Resume Next
Set dbDatabase = DBEngine(0)(0)
dbDatabase.TableDefs.Refresh
Set tdefTable = dbDatabase(strTableName)
' If an error occurred the tabledef object could not be accessed and
' therefore doesn't exist. This could cause problems in a secured
environment
' though as access may be denied.
If Err = 0 Then
TableExists = True
Else
TableExists = False
End If
End Function
different code from other postings and have the same problem for most. When a
table does not exits I get the error: Run-time error '3265' Item not found in
this collection. on this line - Set tdefTable = dbDatabase(strTableName)
Here is the last code I tried. I thought the purpose of 'On Error Resume
Next' was to move to the next line of code where in this case function should
return 'false'.
What am I missing? Thanks for suggestions.
Function TableExists(strTableName As String) As Integer
' Checks for the existance of a specific table
'Added the tabledefs.refresh as tables just added in this session weren't
' being picked up.
Dim dbDatabase As Database, tdefTable As TableDef
On Error Resume Next
Set dbDatabase = DBEngine(0)(0)
dbDatabase.TableDefs.Refresh
Set tdefTable = dbDatabase(strTableName)
' If an error occurred the tabledef object could not be accessed and
' therefore doesn't exist. This could cause problems in a secured
environment
' though as access may be denied.
If Err = 0 Then
TableExists = True
Else
TableExists = False
End If
End Function