USE ap_control SELECT 0 USE Ap SCAN rAp = RECNO([Ap]) SELECT ap_control COUNT for ALLTRIM(AP.CL) = ALLTRIM(AP_CONTROL.CL) .and.; ALLTRIM(AP.AP) = ALLTRIM(AP_CONTROL.AP) .and.; ALLTRIM(ap.marca) = alltrim(ap_control.marca) .and.; ALLTRIM(ap.modelo) = ALLTRIM(ap_control.modelo); TO ap_find IF ap_find = 0 =MESSAGEBOX ("Not_found") APPEND FROM ap FOR RECNO() = rAp ELSE =MESSAGEBOX ("Found") ENDIF SELECT Ap endscanBut that whole thing could be done that way (If you use VFP9)
INSERT INTO Ap_Control; SELECT Ap.*; FROM Ap; LEFT JOIN Ap_Control ON ALLTRIM(AP.CL) == ALLTRIM(AP_CONTROL.CL) .and.; ALLTRIM(AP.AP) == ALLTRIM(AP_CONTROL.AP) .and.; ALLTRIM(ap.marca) == alltrim(ap_control.marca) .and.; ALLTRIM(ap.modelo) == ALLTRIM(ap_control.modelo); WHERE Ap_Control.CL IS NULLIf it is possible remove all ALLTRIM() functions from that query. Make sure that you have proper indexes and that statement will be very fast.