MS Access VBA – Delete All Table Records

'---------------------------------------------------------------------------------------
' Procedure : WipeTable
' Author    : CARDA Consultants Inc.
' Website   : http://www.cardaconsultants.com
' Purpose   : Empty all the data of the specified table
' Copyright : The following code may be used as you please, but may not be resold, as
'             long as the header (Author, Website & Copyright) remains with the code.
'
' Imput variables:
' ---------------
' strTblName: Name of the table to delete all the records in.
'
' Revision History:
' Rev       Date(yyyy/mm/dd)        Description
' **************************************************************************************
' 1         2008-Feb                Initial Release
'---------------------------------------------------------------------------------------
Function WipeTable(strTblName As String) As String
On Error GoTo WipeTable_Error
 
    DoCmd.SetWarnings False 'Turn off confirmation prompt to user
   
    DoCmd.RunSQL ("DELETE [" & strTblName & "].* FROM [" & strTblName & "];")
 
    DoCmd.SetWarnings True  'Turn back on confirmation prompt to user

    WipeTable = True
 
If Err.Number = 0 Then Exit Function
 
WipeTable_Error:
    MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf & "Error Number: " & _
    Err.Number & vbCrLf & "Error Source: WipeTable" & vbCrLf & _
    "Error Description: " & Err.Description, vbCritical, "An Error has Occured! "
    Exit Function
End Function

Leave a Reply









Spam protection by WP Captcha-Free