1. CLEAR EVENTS causes vfp to jump to any code after a READ EVENTS, therefore the DELETE is not executed at all. => removed that line
2. if you want to adress the telno field, set lcField ="telno", not telno.
3. xval2 is a string, in the delete you don't want to compare newadsl.telno to juststem(ma)+".telno" but to the value inside, therefore need an addtional eval(). Even better use an alias within the sql for the tables.
plus several other issues.
ma=JUSTSTEM(thisform.text1.value)
USE (ma)
total = Val(THISFORM.TEXT2.VALUE)
RAND(-1)
INDEX ON RAND() TO SYS(2023)+'\RANDOM'
COPY TO NEWADSL NEXT total
SET INDEX TO
ERASE SYS(2023)+'\RANDOM'
DELETE FROM (ma) as original WHERE EXISTS(SELECT * FROM NEWADSL as copy WHERE copy.telno==original.telno)
Pack
Bye, Olaf.