Avatar of ckangas7
ckangas7 asked on

If Query Exists Then...

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
Next
 
If hit = 1 Then
DoCmd.DeleteObject acQuery, "Temp_Store"
End If
If hit = 0 Then
MsgBox ("query not found")
End If

Open in new window

Microsoft Access

Avatar of undefined
Last Comment
ckangas7

8/22/2022 - Mon
Guy Hengel [angelIII / a3]

> I have this but it is not working.  
can you clarify "is not working"?
ASKER
ckangas7

When I try to run it I get:
Compile Error:
User-defined type not defined

and the line Dim db AS DAO.CurrentDB is highlighted.

So I believe what I am trying to do is search the system db for my query.  Apparantly CurrentDB is not valid for this operation???
ASKER CERTIFIED SOLUTION
Guy Hengel [angelIII / a3]

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
ckangas7

Thanks much that did the trick.  That was an easy fix.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes