On Error Resume Next

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
 
B

Brendan Reynolds

Perhaps you have error handling set to 'Break on all errors'? (In the VBA
editor, from the Tools menu select Options, and in the Options dialog select
the General tab.)
 
G

Guest

It sounds as though you don't want Access to display a message in the event
of your error. So in your next statement after the expected error, you
should check for the specific error code. If code is true, then clear the
error by setting Err = 0 and exit function with what ever return value you
like.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top