aeolianje
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
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
select name from mSysObjects where Name = 'yourreportname'
or
dlookup("Name","mSysObject s","Name= 'yourreportname')
or
dlookup("Name","mSysObject
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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(
If Err.Number = 2467 Then CheckReportExists = False Else CheckReportExists = True
End Function
lol...anyone else?
ASKER
Wow!
I never got some many responses in such a short time. Thanks for all your ideas!
je
I never got some many responses in such a short time. Thanks for all your ideas!
je
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