Sometimes error handling isn't the best solution, say when you want the
procedure to continue even if the table doesn't already exist. It's very
difficult to catch an error and resume the procedure from the same point.
In such a case, you could use a TableExist(TableName) function that will
loop through the tabledefs collection and check for the tabledef.Name
property to see if it matches the passed value. Keep in mind though, that
the tabledefs collection will contain ALL datasources (linked) as well as
local tables. And, if you delete a linked table from the FE, it will delete
the link, not the table in the BE.
The function would look something like this, though I'm not exactly sure if
the tabledef collection called currectly
(Application.CurrentProject.TableDefs?? I forget the location of this
collection off the top of my head...)
Function fTableExist(TableName) As Boolean
Dim td As TableDef
For Each td In Application.CurrentProject.Tabledefs
If td.Name = TableName Then
fTableExist = True
Exit For
End If
Next
Exit Function
So, your code could look like this:
....
....
If TableExist(tblName) = True Then DoCmd.DeleteObject...
....
....
hth
--
Jack Leach
www.tristatemachine.com
"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)