Note that an "open query" is a query being deisplayed in
datasheet view. This is something that should not be done
in a runnung application.
What that caveat, you can enumerate them by using a little
VBA code:
Dim db As Database
Dim qry As AccessObject
Set db = CurrentDb()
For Each qry In db.AllQueries
If qry.IsLoaded _
Then DoCmd.Close acQuery, qry.Name
Next qry
Set db = Nothing
Well, I was confused too and used the wrong objects. I
would think I would know better than to trust my own air
code, sorry about that. Let's give this a try:
Dim db As Object
Dim qry As AccessObject
Set db = Application.CurrentData
For Each qry In db.AllQueries
If qry.IsLoaded _
Then DoCmd.Close acQuery, qry.Name
Next qry
Set db = Nothing
Note that IsLoaded applies to all AccessObjects, not just
forms. The QueryDef object does not have an equivalent to
the IsLoaded property and there is no Queries collection in
the Application object.
There's got to be something I'm missing here. Is there a particular
reference I need to add in order to use "AccessObject" as a datatype and
"db.AllQueries"? Also, should "Set db = Application.CurrentData read "Set db
= Application.CurrentDb"?
Dim db As DAO.Database
Dim qry As DAO.QueryDef
Dim intLoop As Integer
Set db = CurrentDb()
For intLoop = (db.QueryDefs.Count - 1) To 0 Step -1
Set qry = db.QueryDefs(intLoop)
If Syscmd(acSysCmdGetObjectState , acQuery, qdf.Name) > 0 Then
DoCmd.Close acQuery,. qdf.Name
End If
Next intLoop
Set db = Nothing
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.