As the others have told you the problem is the REPLACE command and the fact that is a scoped command. REPLACE is scoped to the current work area UNLESS you use the IN clause. The default scope for REPLACE is next 1 record, if the currently selected work area has no table open or is at EOF then there is no NEXT 1 record and so no REPLACE occurs. Using the IN clause tells VFP to use the IN target alias as the scope for the REPLACE command.