Report data disappears when printed (1 Viewer)

kpstrat35

Registered User.
Local time
Yesterday, 18:08
Joined
Aug 15, 2016
Messages
10
MS Access 2007

Report is created via a button. The report contains the same subreport repeated 8 times. This is done mainly for simplicity of looping in the code. There are no master-child links.

All the data in the report is via Elookup calls in the Load_Event of the report. The report does not have a Record Source - so obviously all the textboxes are unbound. This is done for speed and a couple other issues I was having with the report.

The report looks great when opened in Print Preview mode. All the data is correct and visible.

When I print the report, the data does not show up in either the physical printed report or on the PDF. It's like the data is getting lost between the time the print button is pushed and the print output is generated.

The DisplayWhen property is set to Always for the subreport and all the fields.

I've attached a picture of the report in Print Preview and then the PDF with the missing data.
 

Attachments

  • Flight Info PDF.jpg
    Flight Info PDF.jpg
    104.5 KB · Views: 210

sneuberg

AWF VIP
Local time
Yesterday, 18:08
Joined
Oct 17, 2014
Messages
3,506
Aft CG is showing up in the PDF. What's different about that textbox?
 

JHB

Have been here a while
Local time
Today, 03:08
Joined
Jun 17, 2012
Messages
7,732
Do you print the report by clicking a button, or are you printing it choosing the print button in the ribbon line after the report is shown in "Print Preview"?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:08
Joined
May 7, 2009
Messages
19,246
maybe you are using Docmd.OutputTo.
the best way is to use a Query. use your E_lookup within the query.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:08
Joined
May 7, 2009
Messages
19,246
another approached, which is effective is use a function/ sub to set the values of your textbox:

private sub report_load()
call fill_in_report
end sub


private sub fill_in_report()
' transfer all your code in the load event to here
' where you set the value of the textboxes.
me.text1=elookup(.....
...
end sub
 

kpstrat35

Registered User.
Local time
Yesterday, 18:08
Joined
Aug 15, 2016
Messages
10
My bad on not being completely clear about the Aft CG - it is the only field not filled by code. It's value is fixed. Control Source = "263.1".
 

kpstrat35

Registered User.
Local time
Yesterday, 18:08
Joined
Aug 15, 2016
Messages
10
JHB - I've tried printing multiple ways and the result is always the same. I initially was creating the report in Print Preview mode and then just printing from there and also creating a PDF from there - no data.

I've now tried printing from a button (DoCmd.PrintOut). Same result.

arnelgp - I tried your second suggestion (filling the report through a sub called from the Load Event). Same result. No data when I print the report.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 02:08
Joined
Jul 9, 2003
Messages
16,285
I'm not well up on the intricacies of reports I try it and keep mine very simple and basic, doing the Grunt work in the SQL statements because you never know when you might want to use the data else where.

It's my understanding that a report preview gathers the data in a different way. So the fact that the report works in print preview but not when you print it might be due to a problem with it accessing the real data, as opposed to the display data.

Sent from my SM-G925F using Tapatalk
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:08
Joined
May 7, 2009
Messages
19,246
are you sure? coz this is the same code i suggested some weeks ago with your same problem and it worked.

i tested it and it worked also.
 

sneuberg

AWF VIP
Local time
Yesterday, 18:08
Joined
Oct 17, 2014
Messages
3,506
I've attached a very simple database in which Report2 is set up the way you describe your report. You should see A, B, and C in the textboxes. The PDF export of this works on my system. Would you try it on yours?

Could you upload your database?

Edit: Mine not exactly like yours. The ELookup are in the control sources. I'll work on a version that does this in the load event.
 

Attachments

  • UnboundReport.accdb
    424 KB · Views: 120

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:08
Joined
May 7, 2009
Messages
19,246
same thing with mr.sneuberg. report Table1 and Table2 is same report only on the way they gather the data.
 

Attachments

  • AccessReport.accdb
    468 KB · Views: 79

kpstrat35

Registered User.
Local time
Yesterday, 18:08
Joined
Aug 15, 2016
Messages
10
This forum sure does autologoff quick. Lost my last reply.

I have narrowed the problem with your help. It's in the subreports. I placed two textboxes directly on the report. The first is filled via an Elookup call in the code. The second has the Control Source of the textbox = Elookup().

When creating the PDF, those two textboxes retained their data and printed correctly. All the fields on the subreport still have no data.

I'm going to upload my database as soon as I can clean it up. Too much there now to upload.
 

sneuberg

AWF VIP
Local time
Yesterday, 18:08
Joined
Oct 17, 2014
Messages
3,506
Attached is the version that loads data in the report's load event. It doesn't work just like yours so you don't need to test it. I posted it because I said I would. I'll try arnelgp's fix now.
 

Attachments

  • UnboundReportV2.accdb
    424 KB · Views: 71

sneuberg

AWF VIP
Local time
Yesterday, 18:08
Joined
Oct 17, 2014
Messages
3,506
mr arnelgp's suggestion of moving the code in the load event to a subroutine didn't change anything thing. Still doesn't produce a PDF output. I looked the AccessReport database and I don't see much difference between putting the ELookups directly in the control sources and having an intervening function other that perhaps that it would make the control sources of the report simplier.

I wish I knew why but it looks like you can't do this in the load event. You may be stuck with using the control sources.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:08
Joined
May 7, 2009
Messages
19,246
you already have it mr.sneuberg. we have same code:
 

Attachments

  • UnboundReportV2.accdb
    544 KB · Views: 70

sneuberg

AWF VIP
Local time
Yesterday, 18:08
Joined
Oct 17, 2014
Messages
3,506
You can set the control sources of the reports' textboxes during the report load event as I've done in the attached database.
 

Attachments

  • UnboundReportV3.accdb
    432 KB · Views: 72

kpstrat35

Registered User.
Local time
Yesterday, 18:08
Joined
Aug 15, 2016
Messages
10
I have replicated mr. arnelgp's code exactly and yet for some reason, his works but mine does not. I'm trying to upload a copy of mine but I'm having a hard time getting it small enough. Thanks for the continued help. I'll get mine uploaded as soon as possible.
 

kpstrat35

Registered User.
Local time
Yesterday, 18:08
Joined
Aug 15, 2016
Messages
10
Here is the pared down database. The code for the report is the same with the same table. I've removed some of the fields that used queries because it was too much to include and it doesn't really matter.

Click the Open Report button on frmHome. This opens the report in Print Preview with the two textboxes on the report along with the subreport. You'll notice the textboxes in the subreport all have data in them. But once you print, the data in the subreport disappears.

The textbox "450 pph" has the code sampled from mr. arnelgp and you'll notice it doesn't work either.
 

Attachments

  • SubreportTest.accdb
    640 KB · Views: 116

sneuberg

AWF VIP
Local time
Yesterday, 18:08
Joined
Oct 17, 2014
Messages
3,506
The textbox "450 pph" has the code sampled from mr. arnelgp and you'll notice it doesn't work either.

Yes it doesn't and doesn't work with ELookUp either. My test database didn't have criteria in the ELookUp but apparently that's what makes it fail in this case.

If you put a Debug.Print statement in the FillSubReport as shown below

Code:
Public Function FillSubReport(Expr As String, Domain As String, Optional Criteria As Variant)
    
  [COLOR="Blue"]  Debug.Print "Criteria = " & Criteria[/COLOR]
    FillSubReport = ELookup(Expr, Domain, Criteria)
    
End Function

When you open the report you get: Criteria = Leg = 'KFPR-MYEF'

But when you output to PDF you get: Criteria = Leg = ''

I think you going to have to start over again and use the conventional data sources for this report.
 

kpstrat35

Registered User.
Local time
Yesterday, 18:08
Joined
Aug 15, 2016
Messages
10
I have found a way for it to work but I have to set a Record Source for the subreport which is tblSpecificFlightData. I created two textboxes with almost identical Elookup() calls in the Control Sources.

txtA.ControlSource = Elookup("expr", "domain", "criteria = " & txtFlightLegID)
txtB.ControlSource = Elookup("expr", "domain", "criteria = " & txtFlightLegIDTest)

txtFlightLegID.ControlSource = FlightLegID (field from table tblSpecificFlightData)
txtFlightLegIDTest.ControlSource is Unbound and is set in the Load Event.

Kind of like you said above, sneuberg, the criteria gets lost upon printing. But when the criteria is a bound control source, it works.

So what I'm going to try is to just have one textbox on the subreport that is bound. I will then reference it with all of the textbox.controlsource of which i will set in the Load Event.
 

Users who are viewing this thread

Top Bottom