The creation and customization of database applications using Microsoft Access
Hello C.J. P
Please try the following approach:
Sub CheckActiveReport()
Dim rpt As Report
Dim reportName As String
' 1. Attempt to grab the active report
On Error Resume Next
Set rpt = Screen.ActiveReport
On Error GoTo 0
' 2. Check if the object was successfully assigned
If rpt Is Nothing Then
MsgBox "Er is momenteel geen rapport actief.", vbExclamation
Exit Sub
End If
' 3. If we got here, a report is active
reportName = rpt.Name
MsgBox "Actief rapport: " & reportName
End Sub
Instead of relying on Screen.ActiveReport, you might consider using the AllReports collection to check whether a report is actually open and loaded.
If you simply need to determine whether a report is open (regardless of whether it currently has focus), you can use this logic:
If CurrentProject.AllReports("YourReportName").IsLoaded Then
' The report is open, even if it doesn't have focus
End If
If you are trying to retrieve the report name from within the report itself (for example, in a Format or Print event), you can use: Me.Name
Hope this helps. If this doesn't apply to your situation, please feel free to share more details about your Access setup, and I’ll be happy to take a closer look with you.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.