Error in Filter functionality on Dispaly method field on the form

Hi all,

I write following code in the context method on form control for the filter functionality. But when I click remove filter then following error occurs.

"The required QueryBuildDataSource was not found in the Query associated with the FormDataSource '%1 "

and code is -

int selectedMenu;
formrun fr;
Args ag;
Name strtext;
querybuilddataSource qb1;
queryrun qr;
query q;
PopupMenu menu = new PopupMenu(element.hWnd());
int a = menu.insertItem(‘Filter By Field’);
int b = menu.insertItem(‘Filter By Selection’);
int c = menu.insertItem(‘Remove Filter’);
;

selectedMenu = menu.draw();
switch (selectedMenu)
{
case -1: //Filter by field
break;
case a:
ag = new args(‘SysformSearch’);
fr = new formrun(ag);
fr.run();
fr.wait();
//Reading User entered value for filter process
strtext = fr.design().controlName(‘FindEdit’).valueStr();
if(strtext)
{
//Creating a query for filter
q = PurchaseTable_ds.query();
//q = smmBusRelTable_ds.query();
qb1 = q.dataSourceTable(tablenum(PurchTable));
//qb1 = q.dataSourceTable(tablenum(smmBusRelTable));
qb1 = qb1.addDataSource(TableNum(VendPackingSlipJour));
//qb1 = qb1.addDataSource(TableNum(CustTable));
qb1.addLink(FieldNum(PurchTable,PurchId),FieldNum(VendPackingSlipJour,PurchId));
//qb1.addLink(FieldNum(smmBusRelTable,CustAccount),FieldNum(CustTable,AccountNum));
qb1.addRange(FieldNum(VendPackingSlipJour,GRNNumber_IN)).value(strtext);
//qb1.addRange(FieldNum(CustTable,Name)).value(strtext);
PurchaseTable_ds.query(Q);
//smmBusRelTable_ds.query(Q);
PurchaseTable_ds.executeQuery();
//smmBusRelTable_ds.executeQuery();
}
break;

case b: // Filter By Selection
q = PurchaseTable_ds.query();
//q = smmBusRelTable_ds.query();
qb1 = q.dataSourceTable(tablenum(PurchTable));
//qb1 = q.dataSourceTable(tablenum(smmBusRelTable));
qb1 = qb1.addDataSource(TableNum(VendPackingSlipJour));
qb1.addLink(FieldNum(PurchTable,PurchId),FieldNum(VendPackingSlipJour,PurchId));
qb1.addRange(FieldNum(VendPackingSlipJour,PurchId)).value(GRN_Number.valueStr());

PurchaseTable_ds.query(Q);
PurchaseTable_ds.executeQuery();
break;

case c : // Remove Filter
q = new Query();
qb1 = q.addDataSource(tablenum(PurchTable));
qb1.clearLinks();
qb1.clearRanges();
PurchaseTable_ds.query(Q);
PurchaseTable_ds.removeFilter();

break;

Default:
break;
}