Deleting tables when Import files creates _ImportErrort

  • Thread starter Thread starter ReidarT
  • Start date Start date
R

ReidarT

I have an importroutine that adds records to a table.
I have to manipulate the files after import, so Access creates
_importError1, _importError2 and so on.
How can I delete all _importError-tables. The number of errortables differ
from import to import.
regards
reidarT
 
Try pasting this into a standard module; it loops through all the table
names and if it finds "ImportErrors" in the name, it deletes the table.

Sub KillErrorTables()
Dim tdf As DAO.TableDef
Dim strSQL As String
Dim db As DAO.Database

Set db = CurrentDb
For Each tdf In db.TableDefs
If InStr(tdf.Name, "ImportErrors") > 0 Then
strSQL = "DROP Table " & tdf.Name
db.Execute strSQL
End If
Next tdf
Set db = Nothing
MsgBox "Operation Complete"
End Sub
 
Sub DeleteErrorTables()
Dim Tdefs As TableDefs
Dim intX As Integer
Dim intMax As Integer

Set Tdefs = CurrentDb.TableDefs
intMax = Tdefs.Count - 1
For intX = Tdefs.Count - 1 To 0 Step -1
If Left(Tdefs(intX).Name, 12) = "_ImportError" Then
Tdefs.Delete Tdefs(intX).Name
End If
Next intX
End Sub
 
Back
Top