Sub DeleteExistingQuery()
Dim db
Dim qdf
Dim QueryName
Dim Deleted As Boolean
QueryName = InputBox("Please enter the name of the query you wish to delete:", "Delete existing query")
If QueryName <> "" Then
Set db = CurrentDb
For Each qdf In db.QueryDefs
If qdf.Name = QueryName Then
db.QueryDefs.Delete qdf.Name
Deleted = True
Exit For
End If
Next
If Deleted Then
MsgBox QueryName & " succesfully deleted.", vbOKOnly + vbInformation, "Query deleted"
Else
MsgBox QueryName & " not found - check name and try again.", vbOKOnly + vbCritical, "Query not found"
End If
End If
End Sub