lSuccess = .f. Do While Not lSuccess cSQL = "SELECT LastNumber FROM NumberTable WHERE cKey = 'TABLENAME'" if SQLExec(nConn, cSQL) <> 1 * Connection error Exit EndIf nLastNumber = SQLResult.LastNumber nNewId = nLastNumber + 1 cSQL = "UPDATE NumberTable SET LastNumber = nNewID WHERE "+ ; "cKey='TABLENAME' and LastNumber = nLastNumber" if SQLExec(nConn, cSQL) <> 1 * Connection Error Exit EndIf if SQLExec(nConn, 'Select @@Rowcount') <> 1 * Connection error Exit EndIf lSuccess = ( SQLResults.Exp = 1 ) EndDo If ! lSuccess * Indicates a problem and you don't have an id Else * You have a good Id EndIfHope this helps,