Solved

how to determine if a report exists

Posted on 2007-04-10
7
856 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:aeolianje
7 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 18882947
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
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 18882961
select name from mSysObjects where Name = 'yourreportname'

or

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

0
 
LVL 61

Accepted Solution

by:
mbizup earned 250 total points
ID: 18882969
To find if a report exists:

Function FindReport(sRpt As String) As Boolean
    Dim objRpt As AccessObject
    For Each objRpt In CurrentProject.AllReports
        if objRpt.Name = sRpt then
            FindReport = true
            exit for
        end if
    Next
End Function
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 18882972
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
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 18882992


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
0
 
LVL 34

Expert Comment

by:jefftwilley
ID: 18883138
lol...anyone else?
0
 

Author Comment

by:aeolianje
ID: 18883577
Wow!

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

je
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question