ADOQuery Filter
I am having trouble making this code work, it gives me an error that says the parameters are not correct or of the wrong type. I have tried several variations and I can't seem to find one that works.
This is in an OnClick event for an Ok button.
begin
if CheckBox1.Checked = False then
begin
Query1.Filtered := False;
Query1.Filter := "[TARGTAREA]= 'OTA'";
Query1.Filtered := True;
end
else
begin
Query1.Filter.Active := False;
end;
end
If I manually set the filter in the query to [TARGTAREA] = 'OTA' it works OK.
The query is
SELECT x8.TARGTAREA, Count(x2.UniqueID) AS CountOfUniqueID, x2.TASKCODE, x2.TASKMAJR
FROM xprop AS x8, xbldg AS x, xunit AS x11, xloc AS x6, xsurf AS x9, xcase AS x2
WHERE (((x8.SEQ)=[x].[seq]) AND ((x.BSEQ)=[x11].[bseq]) AND ((x11.USEQ)=[x6].[useq]) AND ((x6.LSEQ)=[x9].[lseq]) AND ((x9.SSEQ)=[x2].[sseq]))
GROUP BY x8.TARGTAREA, x2.TASKCODE, x2.TASKMAJR
HAVING (((x8.TARGTAREA) Like :Target))
ORDER BY x8.TARGTAREA, Count(x2.UniqueID) DESC , x2.TASKCODE;
This is in an OnClick event for an Ok button.
begin
if CheckBox1.Checked = False then
begin
Query1.Filtered := False;
Query1.Filter := "[TARGTAREA]= 'OTA'";
Query1.Filtered := True;
end
else
begin
Query1.Filter.Active := False;
end;
end
If I manually set the filter in the query to [TARGTAREA] = 'OTA' it works OK.
The query is
SELECT x8.TARGTAREA, Count(x2.UniqueID) AS CountOfUniqueID, x2.TASKCODE, x2.TASKMAJR
FROM xprop AS x8, xbldg AS x, xunit AS x11, xloc AS x6, xsurf AS x9, xcase AS x2
WHERE (((x8.SEQ)=[x].[seq]) AND ((x.BSEQ)=[x11].[bseq]) AND ((x11.USEQ)=[x6].[useq]) AND ((x6.LSEQ)=[x9].[lseq]) AND ((x9.SSEQ)=[x2].[sseq]))
GROUP BY x8.TARGTAREA, x2.TASKCODE, x2.TASKMAJR
HAVING (((x8.TARGTAREA) Like :Target))
ORDER BY x8.TARGTAREA, Count(x2.UniqueID) DESC , x2.TASKCODE;
Comments
then try to make a dynamic change in THIS ADOQuery within FR script in any event when your report knows what parameters (for TargetArea) are chosen and before THIS ADOQuery is open. I mean 5th line of your select statement holds where clause
ADOQuery1.SQL[ 5] := 'HAVING ...'; // and here should be a string you create on-fly,
where you can manipulate with a string that you assign to ADOQuery1.SQL[ 5] making whole SELECT statement being acceptable by your database engine syntax.
Mick