Eljefegeneo
Still trying to learn
- Local time
- Yesterday, 20:28
- Joined
- Jan 10, 2011
- Messages
- 902
I have a command button on my form frmMain that I used to bring up all the client records that are "Active" (having an open contract). qryActive is the first query shown below. The following code works fine; it filers all the records to show only those that meet the criteria.
DoCmd.OpenForm "frmMain", , , "ClientId In(Select ClientId FROM qryActive WHERE CustomerStatus='Active' )"
But I had to add a T/F check box to include those records for which we wanted to include [KeepActive]= True, which is the second query shown below qryKeepActive.
The Union Query seems to work fine. It runs very fast, less than one second to filter 20K records. But when I tried to use the following code with the Union Query instead of the DoCmd code above, it seems to be in an endless loop or isn't working, no errors, just hangs up.
DoCmd.OpenForm "frmMain", , , "ClientId In(Select ClientId FROM qryOnTheAirUnion)"
What cannot figure out is how to use it to use it to filter the records to select only those that meet the criteria.
SELECT tblMain.ClientID, Min(IIf([ContractsEnds]<Date() Or [DateCancelled]<Date(),"Inactive","Active")) AS CustomerStatus
FROM tblSales INNER JOIN tblMain ON tblSales.ClientID = tblMain.ClientID
GROUP BY tblMain.ClientID
HAVING (((Min(IIf([ContractsEnds]<Date() Or [DateCancelled]<Date(),"Inactive","Active")))="Active"));
UNION ALL SELECT tblMain.ClientID, tblMain.KeepActive
FROM tblMain
WHERE (((tblMain.KeepActive)=True));
What I am attempting with this code is to select all records that meet the first query criteria, that is, are "Active" and the second query criteria, KeepActive = True. The two queries are mutually exclusive; any that are [KeepActive] = True will not be "Active" in the first query.
Any suggestions?
DoCmd.OpenForm "frmMain", , , "ClientId In(Select ClientId FROM qryActive WHERE CustomerStatus='Active' )"
But I had to add a T/F check box to include those records for which we wanted to include [KeepActive]= True, which is the second query shown below qryKeepActive.
The Union Query seems to work fine. It runs very fast, less than one second to filter 20K records. But when I tried to use the following code with the Union Query instead of the DoCmd code above, it seems to be in an endless loop or isn't working, no errors, just hangs up.
DoCmd.OpenForm "frmMain", , , "ClientId In(Select ClientId FROM qryOnTheAirUnion)"
What cannot figure out is how to use it to use it to filter the records to select only those that meet the criteria.
SELECT tblMain.ClientID, Min(IIf([ContractsEnds]<Date() Or [DateCancelled]<Date(),"Inactive","Active")) AS CustomerStatus
FROM tblSales INNER JOIN tblMain ON tblSales.ClientID = tblMain.ClientID
GROUP BY tblMain.ClientID
HAVING (((Min(IIf([ContractsEnds]<Date() Or [DateCancelled]<Date(),"Inactive","Active")))="Active"));
UNION ALL SELECT tblMain.ClientID, tblMain.KeepActive
FROM tblMain
WHERE (((tblMain.KeepActive)=True));
What I am attempting with this code is to select all records that meet the first query criteria, that is, are "Active" and the second query criteria, KeepActive = True. The two queries are mutually exclusive; any that are [KeepActive] = True will not be "Active" in the first query.
Any suggestions?