List of queries

  • Thread starter Thread starter Sheldon
  • Start date Start date
S

Sheldon

In code, How do I get a list of all queries? In reality I
want to delete several queries, through code that ALL
start the same way ie "qrySOC" such as
qrySOCA, qrySOCB, qrySOCM, etc.
SO I need a list of the queries.

Better yet How do I use the command

DoCmd.DeleteObject acQuery, "qrySOCTest"

to delete ALL the qrySOC... queries?

Thanks
 
"Sheldon" said:
In code, How do I get a list of all queries? In reality I
want to delete several queries, through code that ALL
start the same way ie "qrySOC" such as
qrySOCA, qrySOCB, qrySOCM, etc.
SO I need a list of the queries.

Better yet How do I use the command

DoCmd.DeleteObject acQuery, "qrySOCTest"

to delete ALL the qrySOC... queries?

Thanks

Sheldon

You can loop backwards through the QueyDefs collection:


Sub sDeleteQDefs()
Dim intCount As Integer, intPos As Integer
Dim db As Database
Set db = DBEngine(0)(0)
db.QueryDefs.Refresh
intCount = db.QueryDefs.Count - 1
For intPos = intCount To 1 Step -1
If Left(db.QueryDefs(intPos).Name, 6) = "qrySOC" Then
DoCmd.DeleteObject acQuery, db.QueryDefs(intPos).Name
End If
Next intPos
db.QueryDefs.Refresh
Set db = Nothing
End Sub
 
Back
Top