troubleshooting Question

Deleting Queries in Access 2003 using VBA

Avatar of ashercim
ashercim asked on
Microsoft Access
5 Comments1 Solution344 ViewsLast Modified:
I've got an Access 2003 application that I'm developing, and it works great except for 1 remaining bug.

I can't seem to delete a QueryDef from the collection.  The code for this follows:

           For Each qdf In db.QueryDefs
                        'MsgBox (qdf.Name)
                        If qdf.Name = "qryTemp2" Then db.QueryDefs.Delete "qryTemp2"
             Next qdf

This temporary query may or may not be created at some point depending on the options that the user has chosen.  What I'm not understanding is that when qdf.name="qryTemp2" I'm getting a runtime 3011 error saying that the Jet Database Engine could not find the object qryTemp2.

It doesn't show up in the database window, but no matter what I do, I can't seem to remove this name from the Querydefs collection.

By the way, i set qdf as:

Dim qdf As DAO.QueryDef

I haven't had any problems like this in any of the other applications I've been developing and I don't understand it.  Any help would be greatly appreciated.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 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 5 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