code to check if a report exists

holden_1

Registered User.
Local time
Today, 21:49
Joined
Feb 2, 2005
Messages
38
hey, just a quick one, any ideas on a line of code to check if a report exists.. something like IF (report exists) Then...

Cheers
Rob
 
[edited - sorry ignore this, this won't work - it only checks open reports, not the reports container
a proper solution is going to need a bit more work]


put this in a module

Code:
Function reportexists(rname As String) As Boolean

On Error GoTo noreport
reportexists = Reports(rname).Name = rname
Exit Function

noreport:
reportexists = False

End Function

usage

if reportexists("reportname") then

or

reportfound = reportexists("reportname")


-------------
 
can i use this by defining rname in private sub where i intend to use the function? or would i have to write a function for each report i intend to check for with this? bascially, if the report exists, i want to delete it, if it doesn't i want to end the sub.

thanks for your help :)
 
right try this instead - you have to see if the report exists in the report container, as below

Code:
Function reportexists(rname As String)
Dim dbs As Database
Dim ctr As Container

    Set dbs = CurrentDb
    Set ctr = dbs.Containers!Reports

    On Error GoTo noreport
    reportexists = ctr(rname).Name = rname
    
exithere:
    Set dbs = Nothing
    Set ctr = Nothing
    Exit Function
    
noreport:
    reportexists = False
    Resume exithere

End Function

usage

if reportexists("reportname") etc
 
put the function reportexists in a module

then from any where you can say

explicitly
if reportexists("particularreport")

or with a var
if reportexists(reportvar)

without playing, i am not sure excatly what the syntax would be to delete a report

why would you need to do that in code anyway?
 
basically i want to customise the filename of a report i'm exporting to outlook as an .rtf and the only way i seem to be able to do this is by copying the report and assigning it the name, then sendobject. now, if sendobject is cancelled i need to delete the report. as i had it, the report would remain as the line to delete it is bypassed by the error routine. if i add that lien to the error routine it tries todelete something that aint there regardless of the error. the report name is variable.
 

Users who are viewing this thread

Back
Top Bottom