Solved A Report Puzzle (1 Viewer)

Cotswold

Active member
Local time
Today, 23:26
Joined
Dec 31, 2020
Messages
528
I have a report and I wanted to fill fields in the Header before printing using various DLookup() operations and other calculated fields. These are all in the Report Load().

If I run the report by double-clicking, or run it with DoCmd.OpenReport "R34_Test", acViewPreview it is fine.

However, if I run it to the printer with Docmd.OpenReport "R34_Test", acViewNormal the fields in the header do not show content.

Irritatingly I cannot see why. Just wondering if anyone out there knows why.

I attach a database with a simplified Report and Form to run the report as an example.
 

Attachments

  • CotswoldReportErr.accdb
    424 KB · Views: 65

Gasman

Enthusiastic Amateur
Local time
Today, 23:26
Joined
Sep 21, 2011
Messages
14,310
Works for me?
1689429272572.png

using your Print button ?

Ahh I see. I had run the Preview first and still had that open.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 17:26
Joined
Feb 28, 2001
Messages
27,189
Don't know that I can answer the problem, but you are not the first to report this issue.

 

Gasman

Enthusiastic Amateur
Local time
Today, 23:26
Joined
Sep 21, 2011
Messages
14,310
This works
Code:
Private Sub bPrint_Click()
   '
        Dim fReport As String
        fReport = "R34_Test"
        DoCmd.OpenReport fReport, acViewPreview, , , acHidden
        DoCmd.OpenReport fReport, acViewNormal
        DoCmd.Close acReport, fReport
 
  
End Sub

An alternative instead of the extra OpenReport command is put that code from Report Load into the Print Event of the header.
Code:
Private Sub PageHeaderSection_Print(Cancel As Integer, PrintCount As Integer)
    Me!fText0 = "QWERTY"
    Me!fText2 = "ASDFGH"
    Me!fText4 = "ZXCVBN"

End Sub
 
Last edited:

KitaYama

Well-known member
Local time
Tomorrow, 07:26
Joined
Jan 6, 2022
Messages
1,541
Your code should be in Page Header's on format event.
 

Users who are viewing this thread

Top Bottom