VBA Access Function fncDeleteQuery Code Only

This is code only, to learn more see this post:

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


Copy and paste these two functions (blue text) into a module from the Visual Basic Editor of your database.


Function fncDeleteQuery(qName As String)
If fExistQuery(qName) = True Then DoCmd.DeleteObject acQuery, qName
End Function


Function fExistQuery(qName As String) As Boolean
Dim db As DAO.Database, i As Integer
Set db = CurrentDb
fExistQuery = False
db.QueryDefs.Refresh
For i = 0 To db.QueryDefs.Count - 1
If LCase(qName) = LCase(db.QueryDefs(i).Name) Then
fExistQuery = True
Exit For
End If
Next i
Set db = Nothing

End Function

Comments

Popular Posts