MS Access VBA – Delete a Table

'---------------------------------------------------------------------------------------
' Procedure : DelTbl
' Author    : CARDA Consultants Inc.
' Website   : http://www.cardaconsultants.com
' Purpose   : Delete the specified table
' 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:
' ~~~~~~~~~~~~~~~~
' strTable    Name of the table to be deleted
'
' Revision History:
' Rev       Date(yyyy/mm/dd)        Description
' **************************************************************************************
' 1         2008-May-24                 Initial Release
'---------------------------------------------------------------------------------------
Function DelTbl(strTable As String) As Boolean
On Error GoTo Error_Handler
 
    DoCmd.SetWarnings False    'Disable prompts to confirm deletion
    DoCmd.DeleteObject acTable, strTable
    DoCmd.SetWarnings True     'Reenable prompts

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

Leave a Reply









Spam protection by WP Captcha-Free