VBA Access Function fncDeleteTable Code Only

This is code only, go here for a more detailed explanation and tutorial:

            VBA Access Function fncDeleteQuery Tutorial

Copy and paste this function (blue text) into a module from the Visual Basic Editor of your database.

Function fncDeleteTable(strTableName As String)
If fExistTable(strTableName) = True Then DoCmd.DeleteObject acTable, strTableName
End Function

This function requires fExistTable:

Function fExistTable(strTableName As String) As Boolean

100 On Error GoTo fExistTable_err
120 Dim db As DAO.Database
130 Dim i As Integer
140 Set db = CurrentDb
150 fExistTable = False
160 db.TableDefs.Refresh
170 Application.RefreshDatabaseWindow
180 For i = 0 To db.TableDefs.Count - 1
190 If LCase(strTableName) = LCase(db.TableDefs(i).Name) Then
200 fExistTable = True
210 Exit For
220 End If
230 Next i
240 Set db=nothing
250 Debug.Print "fExistTable = " & fExistTable
Exit Function
debug.print erl, err.number, err.description
GoTo fExistTable_exit
End Function


Popular Posts