Clearing tables in Access

This example shows you how to clean up tables in MS Access 2000. Please note: This only functions from within Access, since it uses the DoCmd function.

Option Compare Database

Private Sub Form_Activate()
    [boxTables].RowSourceType = "Value List"
    For Each Item In Application.CurrentDb.tabledefs
        [boxTables].RowSource = [boxTables].RowSource & ";" & Item.Name
End Sub

Create an empty form with two controls, a combobox named "boxTables" and a button named "btnClearTable", then add the next code:

Option Compare Database

Private Sub btnClearTable_Click()
    Dim strSQL As String
    For Each Item In Application.CurrentDb.tabledefs
        DoCmd.SetWarnings warningsoff
        If Item.Name = [boxTables].Value Then
            strSQL = "DELETE " & [boxTables].Value & ".* FROM " & _
                [boxTables].Value & ";"
            DoCmd.RunSQL strSQL
        End If
        DoCmd.SetWarnings warningson
End Sub

You might also like...


 Thamar I was born in a small town in Holland, and currently live in Poland. I'm fluent in English, German, Polish and Dutch, speak a bit of French and Russian. After finishing Information Technologies in ...


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Computer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter” - Eric Raymond