What Report level fields are available to the 'On Print' event (1 Viewer)

GoodyGoody

Registered User
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
 

GoodyGoody

Registered User
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

AWF VIP
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

I’m here to help
Hi Stephen. Just curious, would you still get an error if you used bang instead of dot? For example: Me!RaceEventID
 

jdraw

Super Moderator
Staff member
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

Registered User
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

Super Moderator
Staff member
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

Registered User
thanks for the explanation Pat Hartman. I do like to know why things are happening. Makes it much easier to remember for next time. :)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom