Solved

how to determine if a report exists

Posted on 2007-04-10
7
848 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

910 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

23 Experts available now in Live!

Get 1:1 Help Now