Check if report exists

  • Thread starter Thread starter Chuck
  • Start date Start date
C

Chuck

How can I check if a report exists?

I know how to check if a table or query exists by looking at the TableDefs
or QueryDefs collections but I'm not sure how to check for reports.

Thanks
 
If you have Access 2000 or newer, try the AllReports collection. Another
option would just be to try and refer to the report and trap the error if
the report doesn't exist. You'll have to use a command that would be valid
for a report that isn't open, perhaps try opening the report in hidden mode
so the user doesn't see the check.
 
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
 
Back
Top