Conditional delete object

  • Thread starter Thread starter ChrisR
  • Start date Start date
C

ChrisR

I have a macro that runs an import of a text file. typically there are some
errors that create an error table. To keep from having them buildup I would
like to have a condition to delete object (the error table) before import so
that it removes the last error table. Has to be a condition because if I
don't have a condition and there is no error table, my macro errors out.
Any help would be greatly appreciated.

My only idea on my own is to convert the macro to a module and have it
resume next on error so that it just skips the delete object if the object
is not there.

c-
 
Chris

Try using this code:-

If IsNull(DLookup("[Name]", "MSysObjects", "[Name]= 'MyTable' And [Type] =
1")) = False Then
CurrentDb.Execute "drop table MyTable"
End If

Andy W
 
Chris,

Use the equivalent of this for the Condition of your DeleteObject macro
action...
DLookup("[AField]","YourTable")
 
Back
Top