Having issue using DoCmd.Close acReport if report already open to then open it to get it to "refresh" and could use some advice.
Using Access 2010, Main Form opens with defaulted parameter values, users can change values, etc. Then have some buttons to run/open various querries/reports. I am trying to incorporate a check if report already open or not using an IsReportOpen function I got from co-worker. Basically, if report already open, then first close it and then open it else just open the report if not already open.
I would really appreaciate any suggestions. As code is, when report is open, it DOES NOT "refresh" (i.e. close & reopen), if report is not open, it opens fine.
Here is code.
Using Access 2010, Main Form opens with defaulted parameter values, users can change values, etc. Then have some buttons to run/open various querries/reports. I am trying to incorporate a check if report already open or not using an IsReportOpen function I got from co-worker. Basically, if report already open, then first close it and then open it else just open the report if not already open.
I would really appreaciate any suggestions. As code is, when report is open, it DOES NOT "refresh" (i.e. close & reopen), if report is not open, it opens fine.
Here is code.
Code:
Private Sub cmdRunCR02Report_Click()
On Error GoTo cmdRunCR02Report_Click_Err
If IsReportOpen("rpt_CR02ClassifyEditValidationLevel2ErrorRateReport") = True Then
DoCmd.Close acReport, "rpt_CR02ClassifyEditValidationLevel2ErrorRateReport", acSaveNo
DoCmd.OpenReport "rpt_CR02ClassifyEditValidationLevel2ErrorRateReport", acViewPreview
Else
End If
DoCmd.OpenReport "rpt_CR02ClassifyEditValidationLevel2ErrorRateReport", acViewPreview
cmdRunCR02Report_Click_Exit:
Exit Sub
cmdRunCR02Report_Click_Err:
MsgBox Error$
Resume cmdRunCR02Report_Click_Exit
End Sub
Code:
Function IsReportOpen(strReportName As String) As Boolean
On Error GoTo Error_Handler
If Application.CurrentProject.AllReports(sRptName).IsLoaded = True Then
IsReportOpen = True
Else
IsReportOpen = False
End If
Error_Handler_Exit:
On Error Resume Next
Exit Function
Error_Handler:
MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf & "Error Number: " & _
Err.Number & vbCrLf & "Error Source: IsReportOpen" & vbCrLf & "Error Description: " & _
Err.Description, vbCritical, "An Error has Occured!"
Resume Error_Handler_Exit
End Function