Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Telling if a report is open via code

Status
Not open for further replies.

RSfromCO

Programmer
May 3, 2002
149
US
I have a sub-report that is used in 3 different main reports.

ParentReport1 contains SubReport1
ParentReport2 contains SubReport1
ParentReport3 contains SubReport1

I want SubReport1 to know which of the main reports are currently open. How can I tell if a report is open via code?

Something like
If Reports("ParentReport1").IsOpen then...
If Reports("ParentReport2").IsOpen then...
If Reports("ParentReport3").IsOpen then...

I can't really use the ".Parent" method because in some cases there is another sub-report layer such as:

ParentReport1 contains SubReport1
ParentReport2 contains SubReportX contains SubReport1
ParentReport3 contains SubReportY contains SubReport1

 
Hello:

You would use the AllReports property / collection to do this: Below would cycle through all the reports and print the name if it was loaded.

Sub AllReports()
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentProject
' Search for open AccessObject objects in AllReports collection.
For Each obj In dbs.AllReports
If obj.IsLoaded = True Then
' Print name of obj.
Debug.Print obj.Name
End If
Next obj
End Sub
 
Different way (not my own code but it works) -

Function ReportLoaded(ByVal strReportName As String) As Boolean

Const conObjStateClosed = 0
Const conDesignView = 0

If SysCmd(acSysCmdGetObjectState, acReport, strReportName) <> conObjStateClosed Then
'If Reports(strReportName).CurrentView <> conDesignView Then
ReportLoaded = True
'End If
End If

Exit Function

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top