Access World Forums

Access World Forums (https://www.access-programmers.co.uk/forums/index.php)
-   Queries (https://www.access-programmers.co.uk/forums/forumdisplay.php?f=8)
-   -   What Report level fields are available to the 'On Print' event (https://www.access-programmers.co.uk/forums/showthread.php?t=306846)

GoodyGoody 09-15-2019 10:44 PM

What Report level fields are available to the 'On Print' event
 
Hi, I have a query with a number of columns that aren't printed on the report line but that I was to save to table for each line on the report. In the 'On Print' event I can successfully pick up this particular field (Me.RaceEventID as it happens) from the drop down that appears so Access VBA knows it's in the collection but when I actually run the report VBA gives an error saying it can't field the field Me.RaceEventID. I'd like to know why this is and so is the only work around to 'print' the field on the line but to hide it for printing to to make it explicitly visible to the 'On Print' event? Thanks as usual for any help.
Stephen

Gasman 09-15-2019 10:50 PM

Re: What Report level fields are available to the 'On Print' event
 
Me refers to the form or report.?
That control is not on your report.?

GoodyGoody 09-16-2019 07:21 AM

Re: What Report level fields are available to the 'On Print' event
 
It's all referring to controls on the Report. The Me.RaceEventID field is on the query and is available to the collection within VBA as I can select it in VBA when I type me.etc . It is not explictly anywhere on the report yet hence my suspicion that I need to actually put it in the detail line and hide it so it is available to VBA. But then when I run it it comes up with an error and when I debug it, it says field not found. Thanks
Stephen

Minty 09-16-2019 08:29 AM

Re: What Report level fields are available to the 'On Print' event
 
On a report the fields have to be present to be able to refer to them, unlike a form.

I suspect it's to do with the reports ability to group and total fields on the fly which could get messy if they were only in the underlying query, as the grouping wouldn't have taken place at that point.

theDBguy 09-16-2019 08:40 AM

Re: What Report level fields are available to the 'On Print' event
 
Hi Stephen. Just curious, would you still get an error if you used bang instead of dot? For example: Me!RaceEventID

jdraw 09-16-2019 09:02 AM

Re: What Report level fields are available to the 'On Print' event
 
Stephen,

Can you post a copy of the database so readers can "experience" the issue?
We only need enough data to highlight the issue. You can anonymize a few records if there is some confidentiality involved.

GoodyGoody 09-21-2019 06:21 AM

Re: What Report level fields are available to the 'On Print' event
 
Hi All, thanks for the replys. AS I suspected, it's because on a report the Query fields are available to the Collection but not the OnPrint event unless explcitly declared as Minty above said to. Thanks for the feedback. BTW, me!RaceEventID doesn't work either. Thanks again S

Pat Hartman 09-21-2019 06:32 AM

Re: What Report level fields are available to the 'On Print' event
 
Minty got it almost right.

In a Report, unlike a form, if you want to reference a field from the RecordSource in code, you must bind it to a control. You can make the control tiny and hidden but the field MUST be bound to a control to be available later. The reason is that Access is smarter than we are and for a report, it rewrites our query and substitutes its own version which includes ONLY the fields that are actually bound to controls. This is also why you can't rely on sort order in your RecordSource query but MUST use the Report's own sorting and grouping options to impose a sort order.

GoodyGoody 09-21-2019 06:37 AM

Re: What Report level fields are available to the 'On Print' event
 
thanks for the explanation Pat Hartman. I do like to know why things are happening. Makes it much easier to remember for next time. :)

Pat Hartman 09-22-2019 01:32 PM

Re: What Report level fields are available to the 'On Print' event
 
You're welcome:)


All times are GMT -8. The time now is 08:58 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World