DoCmd.Close acReport not working so report can reopen/refresh

tnmsr2010

Registered User.
Local time
Today, 06:17
Joined
Feb 20, 2013
Messages
25
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.

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
 
My bad, here is correct code for the run report button. I had the "End If" out of place as I was showing co-worker in my text editor.

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
        DoCmd.OpenReport "rpt_CR02ClassifyEditValidationLevel2ErrorRateReport", acViewPreview
    End If
        
cmdRunCR02Report_Click_Exit:
    Exit Sub
cmdRunCR02Report_Click_Err:
    MsgBox Error$
    Resume cmdRunCR02Report_Click_Exit
End Sub
 
This is resolved (not sure how to mark thread).

All I did was close out of Access compacting db and reopened and now it works just fine (report closes if it is already open, then reopens/refreshes and if not already open, report opens). I had been working on a bunch of various stuff for management today and never did close since early this morning.

Thank you.
 

Users who are viewing this thread

Back
Top Bottom