Share via

Access VBA, Screen.ActiveReport.Name not working code stopt no report is present

C.J. P 40 Reputation points
2026-04-21T09:41:12.9166667+00:00

On Error Resume Next

    reportName = Screen.ActiveReport.Name

   If Err.Number <> 0 Then

MsgBox "Is momenteel niet actief.", vbExclamation

Err.Clear

Exit Sub

End If

On Error GoTo 0

Microsoft 365 and Office | Access | Development
0 comments No comments

Answer accepted by question author

Gabriel-N 17,785 Reputation points Microsoft External Staff Moderator
2026-04-21T10:21:08.1733333+00:00

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.

Was this answer helpful?

1 person found this answer helpful.

Answer accepted by question author

AI answer

2026-04-21T09:41:25.5766667+00:00

Screen.ActiveReport only works when a report actually has the focus at run time. If no report is active, trying to read Screen.ActiveReport.Name raises a run-time error, which is why the code stops unless it is wrapped in error handling.

To handle this safely, keep the On Error Resume Next around the Screen.ActiveReport access, then immediately check Err.Number and clear it, as in the example below:

Dim reportName As String

On Error Resume Next
reportName = Screen.ActiveReport.Name

If Err.Number <> 0 Then
    MsgBox "Is momenteel geen rapport actief.", vbExclamation
    Err.Clear
    On Error GoTo 0
    Exit Sub
End If

On Error GoTo 0

' At this point, reportName contains the active report name
' Continue with code that needs the active report

Key points based on the behavior of Screen.ActiveReport and On Error:

  1. Screen.ActiveReport raises an error if no report has the focus. This is expected behavior.
  2. On Error Resume Next lets execution continue after that error so the code can inspect Err.Number.
  3. Err.Number <> 0 indicates that no active report was available; show the message, clear the error, and exit.
  4. On Error GoTo 0 should be called after the check to turn off the inline error handling once it is no longer needed.

If the code still “stops,” verify:

  • That On Error Resume Next is executed before the Screen.ActiveReport.Name line.
  • That no other error occurs later in the procedure while On Error Resume Next is still active.

References:

AI-generated content may be incorrect. Read our transparency notes for more information.

Was this answer helpful?

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.