MS Access: Infamous 'Access can't find the field..." (1 Viewer)

ironfelix717

Registered User.
Local time
Today, 16:14
Joined
Sep 20, 2019
Messages
193
What is the point of detail events (or any of the report events) if the report can't find your fields anyhow. A report is built off a recordsource... which as fields... therefore its reasonable to expect the events should capture those fields. Apparently not.

Desired outcome:
- Set a label's visible property (in the report detail) depending on the record's field.

Reality:
- 'Access can't find the field you are referring to'

I will assume this petty feature is somehow impossible.

Which ive tried...

Report_Current
Detail_Paint
Detail_Format


None of which capture this field.


Regards
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:14
Joined
May 21, 2018
Messages
8,527
May help

Should be able to hide or appear hidden.
 

ironfelix717

Registered User.
Local time
Today, 16:14
Joined
Sep 20, 2019
Messages
193
Now I remember the last time I wasted my time with this simple petty feature...

To reference fields in these events you must capture the field value in a control on the report. Then reference the control value in VBA. Yeah--- very intuitive. Bravo to Microsoft on that peculiar nuance- probably not documented either (y)

So, when you finally wasted an hour on that, you will be sadly disappointed that you 'Can't set the value of this property in the OnPaint event'

Therefore, setting visibility of controls in the detail section of a report (a quite trivial request) is apparently impossible or at the very least so unnecessarily difficult its not worth figuring out. Ludacris right?? :ROFLMAO: I think so too.

- Regards
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 15:14
Joined
Feb 28, 2001
Messages
27,175
Here is an article regarding the sequence of events in reports and report sections.


Be aware that either OnFormat or OnPrint will fire but not both. OnPrint only applies to PrintPreview. OnFormat only applies to Report View.

As to capturing field values, you ARE in a report which has class module potential, so the ME. prefix is operable, I believe. You could use syntax such as Me.recordset.fieldname anywhere in the report except the Report_Open event (because the report opens before the recordset). Detail section events cannot fire until after the report is open, so they should be able to see what is there. That syntax would capture any field in the current record of the report's recordset, as far as I recall.
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 06:14
Joined
Jan 20, 2009
Messages
12,852
To reference fields in these events you must capture the field value in a control on the report. Then reference the control value in VBA. Yeah--- very intuitive. Bravo to Microsoft on that peculiar nuance- probably not documented either (y)
The absence of something does not require documentation.
I believe. You could use syntax such as Me.recordset.fieldname
Unfortunately no.

Access will tell you the story if you try to reference the Recordset property. To put it simply, unlike a Form, Recordset is not usually a Member of the Report object.
 

isladogs

MVP / VIP
Local time
Today, 21:14
Joined
Jan 14, 2017
Messages
18,217
Not quite sure I understand your issue with this.
Just tested. Works perfectly for me using the Detail_Format event

Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    If Me.House = "Mendip" Then Me.LblHouse.visible = False
End Sub

This screenshot shows the House label hidden as the condition is met
1613815661365.png


Different student, Condition not met. Label visible
1613815772609.png
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 15:14
Joined
Feb 28, 2001
Messages
27,175
G., MS documentation says Me.Recordset works.


Are they lying? While it IS Microsoft we are discussing, it's not like they are used-car salesmen.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 21:14
Joined
Sep 12, 2006
Messages
15,653
Now I remember the last time I wasted my time with this simple petty feature...

To reference fields in these events you must capture the field value in a control on the report. Then reference the control value in VBA. Yeah--- very intuitive. Bravo to Microsoft on that peculiar nuance- probably not documented either (y)

So, when you finally wasted an hour on that, you will be sadly disappointed that you 'Can't set the value of this property in the OnPaint event'

Therefore, setting visibility of controls in the detail section of a report (a quite trivial request) is apparently impossible or at the very least so unnecessarily difficult its not worth figuring out. Ludacris right?? :ROFLMAO: I think so too.

- Regards

I don't understand your problem. The recordsource is a query with fields. Those fields are bound to controls, which by default will have the same name as the field.

However, to hide a value, you make the CONTROL not visible. (ie not the field, although it may well be the same name)

so me.somecontrol.visible = false
or even more clearly
me.controls("somecontrol").visible = false
 

isladogs

MVP / VIP
Local time
Today, 21:14
Joined
Jan 14, 2017
Messages
18,217
Hi Dave
Whilst I also don't understand the problem, the OP stated that he wants to hide the control label rather than the actual control
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 21:14
Joined
Sep 12, 2006
Messages
15,653
aah. Thanks Colin. But it's still the same issue, isn't it? You have to find the label attached to the control bound to the field. The label is even more remote to the field itself, isn't it? The label may not even be attached at all.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:14
Joined
May 21, 2018
Messages
8,527
I do not understand the issue but maybe to hide an attached label
me.SomTextBox.controls(0).visible = false
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:14
Joined
Feb 19, 2002
Messages
43,266
o reference fields in these events you must capture the field value in a control on the report.
Since you know the rule, follow it.

The reason that fields "disappear" this way is because Access rewrites the the RecordSource for reports to include ONLY the fields bound to controls. Once you know this. Work around it. It isn't obvious and I don't like it but no one at MS asked me.
 
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:14
Joined
May 21, 2018
Messages
8,527
Now I finally understand the original question.
 

isladogs

MVP / VIP
Local time
Today, 21:14
Joined
Jan 14, 2017
Messages
18,217
I provided a solution in post #6. It will work whether or not its an attached label.
If the field is not included in the report, add it, hidden if necessary.
Or use a DLookup or a function to get the value and, from that, the label can be hidden.
I still don't see that there is a problem.
 
Last edited:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 15:14
Joined
Feb 28, 2001
Messages
27,175
The reason that fields "disappear" this way is because Access rewrites the the RecordSource for reports to include ONLY the fields bound to controls.

Thanks, Pat. I had forgotten that little "gotcha" about reports. I had used .RecordSource before, but never for a field from the recordsource that wasn't used on the form.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:14
Joined
Feb 19, 2002
Messages
43,266
The thing about this "feature" is that Access fools you. You create the report and add the code that references the record source and it works so you save the changes and close the report. Then you open it and your code no longer works??? I'm not sure at what point Access rewrites your record source but once it does, you have to bind the field to a control (hidden is fine) to make it work as the others have mentioned.

The other mystery that knowing this tidbit solves is - why when I change the order by clause in my query does the order by not change on the report? Same reason. Access apparently discards your order by in the query and replaces it with the one defined in the report properties.

The intention of course, is to make the report more efficient. It's just hard to find this information and it is certainly mysterious until you know it. I think MS should warn you when it is saving that it is rewriting the recordSource. That might make you unhappy but at least you would know.
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 21:14
Joined
Jan 14, 2017
Messages
18,217
There is some sensible logic to these decisions:
1. If a field in the record source is not actually included as a control on a report, it wouldn't be possible to reference it in e.g. the Detail_Format event as you can't base formatting on something that 'doesn't exist'
2. Reports have additional sorting and grouping features which provide far more 'power' than that in a query or SQL statement. The record source sorting is discarded as it could conflict with that done on the report itself.
Its a consistent feature in Access: another example is sorting in a union query only depends on the sort value after the final union statement
Wherever two or more 'things' create potential conflicts, Access prevents this by always ignoring one of them
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 06:14
Joined
Jan 20, 2009
Messages
12,852
G., MS documentation says Me.Recordset works.


Are they lying? While it IS Microsoft we are discussing, it's not like they are used-car salesmen.
Maybe it is a version thing. I have not tried it since Access 2007 where it said the feature is only available in an ADP.
 

Gasman

Enthusiastic Amateur
Local time
Today, 21:14
Joined
Sep 21, 2011
Messages
14,274
Maybe it is a version thing. I have not tried it since Access 2007 where it said the feature is only available in an ADP.
That is exactly the error I was getting. :(
 

Users who are viewing this thread

Top Bottom