0

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.

1 Answer 1

5

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
3
  • It works, but I got one problem. Some table names include "-" for example "tblProducts-A" (I know this titling is stupid -.-). This results in a syntax error. How can I solve this??
    – Flow74
    Jul 28, 2016 at 7:34
  • I thought CurrentDb.Execute "Delete * FROM [ " & tdf.Name], dbFailOnError would help. But it doesn't...
    – Flow74
    Jul 28, 2016 at 7:36
  • Yes, you right, forgot about brackets. Edited the answer.
    – Sergey S.
    Jul 28, 2016 at 8:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.