?
Solved

how to determine if a report exists

Posted on 2007-04-10
7
Medium Priority
?
908 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 93

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 750 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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses

777 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