>SELECT ALLBILLS >SELECT COUNT(POS) FROM Allbills WHERE LEFT(ALLTRIM(pos),9)='%%Page: 1' INTO ARRAY nNumberofbillsincurrentfile >nBillend=0 >FOR I=1 TO m. nNumberofbillsincurrentfile >SELECT AllBILLS >LOCATE FOR LEFT(ALLTRIM(POS),9)='%%Page: 1' AND RECNO()>m.nBillEnd && Bill Starts From Here and This is the First Page >nPageonestart=RECNO() >LOCATE REST FOR LEFT(ALLTRIM(POS),9)='%%Page: 2' AND RECNO()>m.nPageonestart && Page One Ends Here >nPageoneend=RECNO() >LOCATE REST FOR LEFT(ALLTRIM(POS),9)='%%Page: 1' AND RECNO()>m.nPageoneend && Next Bills Starts From Here >nBillEnd=RECNO() GO m.nPageOneEnd lcFileName = STREXTRACT(POS,'(',')') >LOCATE REST FOR STREXTRACT(POS,'(',')')='Account Number' AND RECNO()>m.nPageoneend AND RECNO()<m.nBillend >SKIP Don't use oFilename. o is usually used for an object variable type. This will be very confusing. It should be cFileName >cFileName=STREXTRACT(POS,'(',')') >cFileName='D:\HARSH\'+oFileName+'.Ps' Are you near the record you want below after the SKIP above? LOCATE FOR cannot optimize the following without an index. But if the next few records after the above contains the string you seek, you could do LOCATE REST FOR and it will get there really fast. >LOCATE REST FOR ALLTRIM(POS)="20.699 184.238 MV (. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .)S" >Replace POS WITH '20.699 184.238 MV (. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . )SH' If the above is really what you mean to do, it seems the only difference is adding an H to the end of POS. Here's how: REPLACE POS WITH ALLTRIM(POS) + "H" SELECT cannot use RECNO() to optimize. DO NOT ADD AN INDEX ON RECNO()!!! Very dangerous. >SELECT POS FROM Allbills INTO CURSOR Splitfile Where RECNO()=>m.nPageoneend AND RECNO()<m.nBillEnd Readwrite I think you might try.. GO m.nPageoneend COPY REST TO splitfile.DBF WHILE RECNO()<m.nBillEnd USE splitfile in select("splitfile") SELECT splitfile >Set Textmerge ON >Set Textmerge To (m.cFileName) Noshow >SCAN >\\<< TRIM(POS) >> >\ >ENDSCAN >Set Textmerge To >Set Textmerge OFF *DO NOT EVER USE RECNO() with SQL commands. >DELETE FROM Allbills Where RECNO()=>m.nPageonestart AND RECNO()<=m.nBillEnd Do this instead. SELECT ALLBILLS GO m.nPageOneStart DELETE REST WHILE RECNO()<=m.nBillEnd >WAIT WINDOW I Nowait >ENDFOR >