OKay, this code has been working for a while now. Today, I open up the database and test it before moving on to another project and it is no longer working. And I don't know why.
Name of Query is actually a variable that passes through. Which works fine.
It was, for reasons I'm not sure of, using CurrentDB.TableDefs and acTable... which worked..and now doesn't. So I switched it to Querydefs.
Now, if the query Exists, then it does what it should do. It deletes the Query.
however, if it doesn't exist, it pops up with an error saying "item not found in this collection".
Before, it would just move on, now it doesn't.
And I don't know why. No code was changed since the last time I opened this database up.
Code:
On Error Resume Next
Exists = IsObject(CurrentDb.QueryDefs("NameofQuery"))
If Exists Then
DoCmd.DeleteObject acQuery, "NameofQuery"
End If
Name of Query is actually a variable that passes through. Which works fine.
It was, for reasons I'm not sure of, using CurrentDB.TableDefs and acTable... which worked..and now doesn't. So I switched it to Querydefs.
Now, if the query Exists, then it does what it should do. It deletes the Query.
however, if it doesn't exist, it pops up with an error saying "item not found in this collection".
Before, it would just move on, now it doesn't.
And I don't know why. No code was changed since the last time I opened this database up.