Delete tables in a database

D

duffer 54

I need to delete multiple tables in a database, only if they exist, before I
import the new table swith the same name. i was able to use the DoCMD.Delete
object to delete all the tables. How do I add the conditional, if the tables
exist.

Thanks,

Martin
 
M

Mark A. Sam

Martin,

If you try to delete a non existant table like this:

CurrentDb.TableDefs.Delete ("Some TableName")

it will deliver error 3265 which you could trap like this:


Err_Section:
If err = 3265 then
Resume Next
Else
msgbox "Error " & err & ": " & Err.Description
End If

God Bless,

Mark
 
O

Ofer Cohen

You can try

If DCount("*","MsysObjects","[Name]='" & TableName & "'") > 0 Then
CurrentDb.TableDefs.Delete TableName
End If
 
Top