Pages

Wednesday, December 28, 2011

Check If Query Name Exists If Found Then Delete It

If you want to check if query exists or not . if found then delete it from access table.

Here is the code-

Sub check_if_QUERY_exits_and_delete_it()
Dim QRY As DAO.QueryDef
Dim found As Boolean
Dim QRY_name_to_check As String
QRY_name_to_check = "Query1"
found = False
For Each QRY In CurrentDb.QueryDefs
If QRY.Name = QRY_name_to_check Then
found = True
Exit For
End If
Next
If found = True Then
CurrentDb.QueryDefs.Delete QRY_name_to_check
RefreshDatabaseWindow
MsgBox "Query Found and deleted", vbInformation
Else
MsgBox "Query Not Found", vbInformation
End If
End Sub

Download Access Database

No comments:

Post a Comment