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.
Your code works as expected in my test database. Then the query exists, it's deleted, else nothing happens.
Make sure you see all hidden objects and also that there is no naming conflict (a table with that same name, for example). If all else fails, try it in a new blank database, you will see there is nothing wrong with your code.
(°v°)