Thanks. I had already tried the AllReports collection but the help file for
it says that you can't delete an object from the collection, which is what I
need to do.
I am now using the AllReports collection to get the names of all the reports
and the report count. The names are saved to an array. I then loop through
the array and delete the reports that I want. This is the code I am using.
If anyone can suggest something better, please do:
Dim obj As AccessObject, dbs As Object, strReport() As String
Set dbs = Application.CurrentProject
ReDim strReport(dbs.AllReports.Count)
i = 0
For Each obj In dbs.AllReports
i = i + 1
strReport(i) = obj.Name
Next obj
For j = 1 To i
If Left(strReport(j), 5) = "~temp" Then
' Before deleting, need to close the report, if it is open.
DoCmd.Close acReport, strReport(j)
' Delete the report
DoCmd.DeleteObject acReport, strReport(j)
End If
Next j