>>*//////////////////////////////////////////////////////////// >>function GenMatchEvent >>LOCAL liRecno, lnOldSelect, lcOldOrder >> >>lnOldSelect = select(0) >>lcOldOrder = order() >>SELECT MatchQue >> >>liRecno = RecycleIflDeleted() && Returns RecNo to Recycle, >> && or –1 if no recyclable records >> && are available >>IF liRecno = -1 >> INSERT into MatchQue (icallnum,cfleet,cvehicle,cMatchtype,tRefTime) ; >> values (tiID,tcFleet,tcID,tcType,ttRefTime) >>ELSE >> BLANK >> REPLACE MatchQue.icallnum with tiID ,; >> MatchQue.cfleet with tcFleet,; >> MatchQue.cvehicle with tcID ,; >> MatchQue.cMatchtype with tcType ,; >> MatchQue.tRefTime with ttRefTime in "MatchQue" >> unlock record liRecno >>ENDIF >> >>SELECT (lnOldSelect) && Restore original >>SET order to &lcOldOrder && Restore original >> >> >>*//////////////////////////////////////////////////////////// >>function RecycleIflDeleted() >>local lnReturnedRecNo, lnOldSelect, lcOldOrder, lnOldReprocess >> >>tcTableName = alias() >>lnOldSelect = select(0) >>lcOldOrder = order() >>lnOldReprocess = set("reprocess") >> >>select (tcTableName) >>set order to MyDeleted && indexed on MatchQue.lDeleted >>set reprocess to 1 >> >>lnReturnedRecNo = -1 && Initialize as Recyclable (lDeleted = .t.) >> && record not found >>if seek(.t.) >> do while !eof() and lDeleted >> if rlock() >> if lDeleted && Didn't changed while getting >> lnReturnedRecNo = recno() && the lock so we will send back >> exit && it's record # for recycling. >> else >> unlock record recno() && unlock JUST this one >> endif >> endif >> >> skip >> enddo >>endif >> >>select (lnOldSelect) >>set order to &lcOldOrder >>set reprocess to lnOldReprocess >> >>return lnReturnedRecNo >>>There is an article on my web site about corruption that may give you some ideas.