Changing from Report to Preview view freezes report

Jeff H
4StarLounger
Posts: 415
Joined: 31 Oct 2017, 20:07

Changing from Report to Preview view freezes report

Post by Jeff H »

From the dashboard I open a parameters form and from there I open a report in Report View. Works fine. This way the users open it to browse.

But they will need to be able to print it. I added a button with this Click event:

Code: Select all

Private Sub cmdPrint_Click()
DoCmd.OpenReport "rptMonthly", acViewPreview
End Sub
Seems simple enough, and it does open Print Preview using the same filter, but it freezes the app. I have to right-click the taskbar icon and click Close Window to crash out of the application. I looked online but didn't find any examples of a similar problem.

I'm thinking that maybe I need to close the Report view and reopen the report in Preview. If that's the case, then I'll need to redesign the parameter variables in order to rerun the same filter directly from the report instead of from the parameters forms.

- Jeff

User avatar
HansV
Administrator
Posts: 78463
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Changing from Report to Preview view freezes report

Post by HansV »

Why don't you open the report in Print Preview directly? Users can still view all pages that way.

As you have found, switching from Report View to Print Preview will freeze the database...
Best wishes,
Hans

Jeff H
4StarLounger
Posts: 415
Joined: 31 Oct 2017, 20:07

Re: Changing from Report to Preview view freezes report

Post by Jeff H »

Hmm. Ok, if that's a standing bug it makes sense to use the Print Preview. I've found scrolling a long report to be advantageous, but you're quite right, it can be perused pretty much as easily in paginated form.

Thanks.
- Jeff

Jeff H
4StarLounger
Posts: 415
Joined: 31 Oct 2017, 20:07

Re: Changing from Report to Preview view freezes report

Post by Jeff H »

Unfortunately, that isn't working the way I've got it set up and I can't figure out what to change. Here's the code on the parameter form that opens the report:

Code: Select all

Private Sub cmdOk_Click()
...
sRptLabel = Me.txtReportLabel
rptWhere = "SvcMonth Between " & dStart & " And " & dEnd

DoCmd.OpenReport ReportName:="rptMonthly", View:=acViewReport, _
    WhereCondition:=rptWhere
    
With Reports!rptMonthly
    .lblPeriod1.Caption = sRptLabel
    .lblPeriod2.Caption = sRptLabel
    .Requery
End With

DoCmd.Close acForm, Me.Name
End Sub
It works as written for Report view. But when I change it to acViewPreview, it crashes at ".Requery". The error says the report isn't open and the label captions don't get the date range that I'm trying to pass with sRptLabel. It seems that Print Preview is a different kind of animal than Report View and I don't know how to get those labels populated.

- Jeff

User avatar
HansV
Administrator
Posts: 78463
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Changing from Report to Preview view freezes report

Post by HansV »

You'll have to use the On Open or On Load event of the report to set the captions of the labels.

You can change sPrtLabel to a public variable in a standard module for this purpose.

Or use TempVars:

In cmdOK_Click:

Code: Select all

    TempVars.Add "sRptLabel", Me.txtReportLabel
In the On Open or On Load event of the report:

Code: Select all

    Me.lblPeriod1.Caption = TempVars!sRptLabel
    Me.lblPeriod2.Caption = TempVars!sRptLabel
    TempVars.Remove "sRptLabel"
Best wishes,
Hans

Jeff H
4StarLounger
Posts: 415
Joined: 31 Oct 2017, 20:07

Re: Changing from Report to Preview view freezes report

Post by Jeff H »

Beautiful!! Works great. Nice tip about TempVars.

Thanks Hans.