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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I tell if a report is already open? 1

Status
Not open for further replies.

striker73

MIS
Jun 7, 2001
376
US
Is there anyway to determine if a specific report is already open? I have a form that adds filters to my report and if it is already open, the filters don't get applied the second time. Any ideas? Thanks!!
 
This is the code I'm trying to use:

Dim accApp as Access.Application
Set accApp = GetObject(, "Access.Application")

With accApp
For Each Report in accApp.Reports
MsgBox("A report is open!")
If (Report.Name = stDocName) Then
MsgBox ("This report is the one you're
trying to open!")
Report.Close
End If
Next Report
End With


Theoretically this should be somewhere in the ballpark, but it's not really working out. When I have a report open (not the one I'm looking for), I get stuck in an infinite loop that keeps saying "A report is open!" Any ideas? Thanks!
 
This code returns true or false to tell you whether a report is open or closed.

[tt]
Function IsRptLoaded(ByVal strReportName As String) As Integer

IsRptLoaded = False
Dim rpt As Report
For Each rpt In Reports
If rpt.Name = strReportName Then
IsRptLoaded = True
Exit For
End If
Next rpt

End Function
[/tt]

Usage:

?IsRptLoaded("MyReportName")

HTH Joe Miller
joe.miller@flotech.net
 
Thanks! That works great! What would be the syntax to close a report that is already open? I tried adding: rpt.Close inside the for loop, but that's not a valid command. Any ideas? Thanks!
 
Here's the code using my function to close a report:

If IsRptLoaded("MyReportName") Then
DoCmd.Close acReport, "MyReportName"
End If

HTH Joe Miller
joe.miller@flotech.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top