Delete tables in a database

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
You can try

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