Link to home
Start Free TrialLog in
Avatar of aeolianje
aeolianjeFlag for United States of America

asked on

how to determine if a report exists

I have a custom reporting application -- that has functionality in it that backs up and restores custom reports.  I keep a table that lists the report names.  While testing - the restore process works fine as long as the reports exist in the backup file.  But when I test the negative condition (report does not exist in the backup file) -- it doesn't know what to do....

How can I determine if a report exists?  I use the following code to check if a query (or table) exists -- but it doesn't seem to recognize reportdef....
    Set dbs = CurrentDb
    dbs.QueryDefs.Refresh
    For Each qdf In dbs.QueryDefs
        If qdf.Name = "Temp_Query" Then
            dbs.QueryDefs.Delete qdf.Name
        End If
    Next qdf

Thanks for the help,
je
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Hello aeolianje,

Function QdfExists(QryName As String) As Boolean
    Dim dbs As DAO.Database
    Dim qdf As DAO.QueryDef
    Set dbs = CurrentDb
    dbs.QueryDefs.Refresh
    For Each qdf In dbs.QueryDefs
        If qdf.Name = QryName Then
            QdfExists = True
            Exit Function
        End If
    Next qdf

    QdfExists = False

End Function


That function will test for the existence of a query, and return True if it exists and False if not.



Regards,

matthewspatrick
select name from mSysObjects where Name = 'yourreportname'

or

dlookup("Name","mSysObjects","Name= 'yourreportname')

ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
try this

Function reportExists(sReport As String) As Boolean
reportExists = False
Dim d As Document, c As Container, db As DAO.Database
    Set db = CurrentDb()
    Set c = db.Containers("Reports")
    For Each d In c.Documents
        If d.Name = sReport Then
            reportExists = True
            Exit Function
        End If
    Next d

End Function


How about this?


Public Function CheckReportExists(ByVal sReport As String) As Boolean
   
    Dim s As String
   
    On Error Resume Next
   
    Err.clear
    s = CurrentProject.AllReports(sReport).Name
   
    If Err.Number = 2467 Then CheckReportExists = False Else CheckReportExists = True
   
End Function
lol...anyone else?
Avatar of aeolianje

ASKER

Wow!

I never got some many responses in such a short time.  Thanks for all your ideas!

je