LOCAL lcDoc,lntotrec lcDoc=ALLTRIM(THIS.VALUE) THISFORM.expgrid.RECORDSOURCE='' * What is the meaning of data in PRODEXP table, shown in the grid initially? * Looks like it has the data from the previous search * so really it works as a temporary cursor. IF EMPTY(THIS.VALUE) MESSAGEBOX("Please enter the GI No. ",0) RETURN * Should be RETURN 0 here, if you want to keep the focus in the textbox. * and better to have more data handling here to let the user at least * close the form without entering anyting ENDIF IF lcDoc='99' RETURN .T. ENDIF SELECT 1 * It is not a good practice to use work area numbers * You should use SELECT 0 and then refer the workareas by alias names USE EXP!junk2 * Here you just dumped your PRODEXP table and opened the view instead * Junk2 is the parameterized remote view. Since I don't have your remote database * I extracted the view definition through GENDBC.PRG *!* CREATE SQL VIEW "JUNK2" ; *!* REMOTE CONNECT "sqlanywhere" ; *!* AS SELECT Transactiondetails.ProductCode, ; *!* Productmaster.ProductDescription, ; *!* Productmaster.ManufUniqueId, ; *!* Productmaster.ProdAreaIdentifier1Id, ; *!* Transactiondetails.PackSize, ; *!* Transactiondetails.PacksQuantity, ; *!* Transactiondetails.TotalSinglesQuantity, ; *!* Transactiondetails.trancurrsnglcostprcinctax-Transactiondetails.trancurrsnglcosttax AS unitcost, ; *!* Transactiondetails.acctcurr1costvalueinctax-Transactiondetails.acctcurr1costtax AS totalcost,; *!* TRANSACTION.DocumentNumber ; *!* FROM DBA.Transactiondetails Transactiondetails,; *!* DBA.TRANSACTION TRANSACTION, ; *!* DBA.Productmaster Productmaster ; *!* WHERE TRANSACTION.LocCreatedClientNumber = Transactiondetails.LocCreatedClientNumber ; *!* AND Productmaster.ProductCode = Transactiondetails.ProductCode ; *!* AND Transactiondetails.TransactionNumber = TRANSACTION.TransactionNumber ; *!* AND TRANSACTION.DocumentNumber = ?lcDoc COUNT TO lntotrec * You don't need to use COUNT TO * as you can just get "RECCOUNT("junk2") * or check _TALLY IF lntotrec=0 MESSAGEBOX("Please enter the correct GI No or try another one ",0) RETURN * Similar comment as above. You should handle where * the focus goes after textbox validation ENDIF IF USED('prodexp') USE IN prodexp * Why close PRODEXP anyway, if it gets reopen again with no changes in between? ENDIF SELECT 2 USE EXP!prodexp IN 0 SET ORDER TO TAG 2 SEEK lcDoc IF FOUND() MESSAGEBOX("This GI No already exists try another ",0) RETURN ELSE APPEND FROM DBF('junk2') * ?? Why APPEND the new data from the remote view to the table ; * which previous content is questionable? ENDIF THISFORM.expgrid.RECORDSOURCE='prodexp' SET FILTER TO documentnumber=ALLTRIM(THISFORM.text1.VALUE)&&lcDoc * Why not just use lcDoc here? And you should refer it consistently * since you already used ALLTRIM(THIS.VALUE) for the same above. * I guess here is where you get only one record, while you expect * to see more. * If your SEEK failed by whatever reason, you may even see * the record which was in PRODEXP already, while your view may be brought nothing. * You should to trace this method and look what's in your remote view * and try to REQUERY it manually trying different values in your lcDoc parameter * to see if it really works the way you want it to. * GO TOP THISFORM.expgrid.REFRESHAnyways, I think that the data design and the workflow in this form should be changed to something more reliable.