You didn't say whether you were using VFP or some other data store (SQL Server maybe?). What about calling a stored procedure? Pass all the necessary data as parameters and let the stored procedure handle the logic of figuring out whether to update an existing row or insert a new one.