troubleshooting Question

If Query Exists Then...

Avatar of ckangas7
ckangas7 asked on
Microsoft Access
4 Comments1 Solution673 ViewsLast Modified:
I am trying to write some vba code that will find out if a query object exists in an access database.  If it exists than it will be deleted.  I have this but it is not working.  Can someone help?

Dim db As DA0.CurrentDb
Dim q As DAO.QueryDef
Dim hit As Byte
For Each q In db.QueryDefs
If q.Name = "Temp_Store" Then hit = 1
If hit = 1 Then
DoCmd.DeleteObject acQuery, "Temp_Store"
End If
If hit = 0 Then
MsgBox ("query not found")
End If
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros