Update Yes/No on One table depending on Set of Records on another

H

Hotshots

Hi! I'm really locked up with this. Here's my situation---
I have two tables tbl1 and tbl2 (one to many) related by the field
"myID".
I have a Yes / No field in each table named Executed on the tbl1 and
Completed on the tbl2.
What i want is " when thru another form 'Form1' i run a update for the
'myID' (i use a text box named 'myID' and a command button named
'Update'), i want to check if the 'Completed' in tbl2 is true for ALL
Records; if So then update in tbl1 and set Executed to True.

The Problem i face here is " HOW TO CHECK FOR A VALUE ON ALL RECORDS
FILTERED BY A CRITERIA" .
If i use the following code even if one of the records has completed
true it sets the executed to true.for all records rather than the
specified myID that i want.
"UPDATE tbl1 INNER JOIN tbl2 ON tbl1.myID = tbl2.myID" & _
" SET tbl1.Executed = True" & _
" WHERE tbl2.completed = True"

I would really appreciate any help as i face similar problems on few
more of my tables.

Thanks in Advance
 
J

John Spencer

One method that might work

UPDATE tbl1
SET tbl1.Executed = True
WHERE tbl1.MyID IN (
(SELECT tbl2.myID
FROM tbl2
GROUP BY tbl2.MyID
HAVING Count(tbl2.MyID) = Abs(Sum(tbl2.Completed=True)))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top