MS Access VBA – Delete All Table Records

Ever needed to wipe a table, delete all the records within a specified table? The following procedure will do exactly that.

'---------------------------------------------------------------------------------------
' Procedure : TableWipe
' Author    : Daniel Pineault, CARDA Consultants Inc.
' Website   : http://www.cardaconsultants.com
' Purpose   : Delete all the records form a tble
' Copyright : The following may be altered and reused as you wish so long as the
'             copyright notice is left unchanged (including Author, Website and
'             Copyright).  It may not be sold/resold or reposted on other sites (links
'             back to this site are allowed).
'
' Input Variables:
' ~~~~~~~~~~~~~~~~
' sTbl      : Name of the table to empty/wipe
'
' Usage:
' ~~~~~~
' Call TableWipe("tbl_Contacts") 'Deletes all the records from the tbl_Contacts table
'
' Revision History:
' Rev       Date(yyyy/mm/dd)        Description
' **************************************************************************************
' 1         2016-09-02              Initial Release
'---------------------------------------------------------------------------------------
Public Sub TableWipe(sTbl As String)
On Error GoTo Error_Handler
    Dim db                    As DAO.Database
    Dim sSQL                  As String
    
    Set db = CurrentDb
    sSQL = "DELETE FROM [" & sTbl & "];"
    db.Execute sSQL
    
Error_Handler_Exit:
    On Error Resume Next
    Set db = Nothing
    Exit Sub

Error_Handler:
    MsgBox "The following error has occurred." & vbCrLf & vbCrLf & _
           "Error Number: " & Err.Number & vbCrLf & _
           "Error Source: TableWipe" & vbCrLf & _
           "Error Description: " & Err.Description, _
           vbCritical, "An Error has Occurred!"
    Resume Error_Handler_Exit
End Sub