Search code examples
vbams-accesssql-delete

MS Access: Empty all tables in DB


Is there a possibility to empty every table of my DB? Obviously there is one way to use:

CurrentDb.Execute "DELETE FROM Table1", dbFailOnError

for every table.

But then I have to use this code for every table. It would be nice if there was a solution with Loop or something which is not related to the tables names.


Solution

  • You can loop thru all local tables using code

    Dim tdf As TableDef
    
    For Each tdf In CurrentDb.TableDefs
        If Left(tdf.Name, 4) <> "MSys" Then
            CurrentDb.Execute "DELETE * FROM [" & tdf.Name & "]", dbFailOnError 
        End If
    Next
    End Sub