VBA Access Function fncDeleteTable Code Only

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

            VBA Access Function fncDeleteQuery Tutorial
            http://www.vbquick.com/2011/10/function-delete-query-microsoft-access.html

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
fExistTable_exit:
240 Set db=nothing
250 Debug.Print "fExistTable = " & fExistTable
Exit Function
fExistTable_err:
debug.print erl, err.number, err.description
GoTo fExistTable_exit
End Function

Do you like this post? Please link back to this article by copying one of the codes below.

URL:

HTML link code:

BB (forum) link code:

No comments:

Post a Comment