Solved

how to determine if a report exists

Posted on 2007-04-10
7
837 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 119

Expert Comment

by:Rey Obrero
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now