Field Type Width TableName C 40 LastID INow use this code to create a new value;
PROCEDURE GetNewKey( pcTable ) LOCAL lcAlias, liNewID * Same current work area lcAlias = ALIAS() IF NOT USED( "Syskeys" ) * If syskeys is not open USE SysKeys ALIAS Syskeys AGAIN IN 0 ENDIF * Select the syskeys table and set the index order SELECT Syskeys SET ORDER TO TableName * Find the record for the table requested SEEK pcTableName IF NOT FOUND() * If there is no record for the table, make one APPEND BLANK ENDIF * Lock the record so no one else can get an id while you are in process DO WHILE NOT RLOCK() ENDDO * Increment the lastKey field to the variable liNewID = LastID + 1 * Update the record with the newly assigned ID REPLACE TableName WITH pcTable, ; LastID WITH liNewID * Unlock the record to let others in UNLOCK * Restore the work area IF NOT EMPTY( lcAlias ) SELECT ( lcAlias ) ELSE SELECT 0 ENDIF * Return the new ID RETURN liNewIDYou can call this function from the Default Value property of the Primary key field in the database as; GetNewKey( "TheTablesName" ).