Avatar of jdallain
jdallain
 asked on

Subquery not working in report

Experts,

I have a subquery that works fine in the query (qryNA3), but when I run a report (qryNA3 as record source) I get the error below. When I remove the subquery, the report works fine. Thank you very much. James
MRAA: IIf(IsNull((select max(ADate) from tblNAPatient where tblNAPatient.AType="Annual Assessment" and tblNAPatient.PID=qryNA2.PID)),(select max(ADate) from tblNAPatient where tblNAPatient.AType="Initial Assessment" and tblNAPatient.PID=qryNA2.PID),(select max(ADate) from tblNAPatient where tblNAPatient.AType="Annual Assessment" and tblNAPatient.PID=qryNA2.PID))

Open in new window

error.JPG
Microsoft AccessSQL

Avatar of undefined
Last Comment
jdallain

8/22/2022 - Mon
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)


If you go into report design, click in the Record Source, open the SQL and run it ... what happens ?

mx
jdallain

ASKER
Just a second.
jdallain

ASKER
Sorry, it's a different record source. But it has qryNA3 (the main query) in it.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
jdallain

ASKER
I guess I need to run the subquery from the final query?
ASKER CERTIFIED SOLUTION
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
jdallain

ASKER
I had to changed the qryNA2 to qryNA3, but it didn't work. Just got the same error with qryNA3.
jdallain

ASKER
The qryNA3.PID is there. It works when I put it in qryNA3 and switch it back to qryNA2.PID.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
jdallain

ASKER
I have 3 queries linked to a different ID number (AID) in the report's query. When I removed them, it worked.
jdallain

ASKER
They are all LEFT JOINED.
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)

Are you SURE that qryNA2.PID is a displayed field in the Record Source ?

mx
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
jdallain

ASKER
It didn't work when I switched to INNER JOIN either.
jdallain

ASKER
Yeah. I think the problem revolves around the links to AID, which is a different ID#.
jdallain

ASKER
I had the switch to qryNA3.PID
final.JPG
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
jdallain

ASKER
It works when I remove queries attached to AID in qryNA3
Jeffrey Coachman

So, ... Problem solved?
jdallain

ASKER
Thanks mx! I'll run some seperate querywith the subquery
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)

"Grade:  A - "Thanks mx! I'll run some seperate querywith the subquery"  "

ooook.

thx.mx
jdallain

ASKER
I didn't have to have that subquery in that query, but it would have been easier. It works for now. I'm sure I'll have to post a follow-up question in a few weeks though. Thanks again mx. James