If in multi-user scenario, you'll need to temporarily perform an RLOCK on the lookup table that holds the sequence counter to ensure that other users don't get the same number.
My adaptation:
FUNCTION NewKeyID
LPARAMETER tcAlias
* tcAlias is the name of the table which needs a unique key value
LOCAL lcAlias, lcID, lcOldReprocess, lnOldArea
lnOldArea = SELECT()
IF PARAMETERS() < 1 then
lcAlias = UPPER(ALIAS())
ELSE
lcAlias = UPPER(tcAlias)
ENDIF
lcID = ""
lcOldReprocess = SET('REPROCESS')
*-- Lock until user presses Esc
SET REPROCESS TO AUTOMATIC
IF NOT USED("SETUP"

then
USE lookupdb!setup IN 0 shared
endif
IF SEEK(lcAlias,"setup","keyname"

then
IF RLOCK("setup"

then && will wait for lock if necessary
lcID = setup.keyvalue
REPLACE keyvalue WITH (lcID + 1) IN SETUP
UNLOCK in "setup"
ENDIF
else
messagebox("Cannot find " + lcAlias + " in LOOKUPDB!SETUP table for unique key generation.",16,"Unique key generation problem."

ENDIF
SELECT (lnOldArea)
SET REPROCESS TO lcOldReprocess
RETURN lcID
ENDFUNC && NewKeyID
HTH,
--Michael
Michael J. Babcock, MCP
Founder, Central PA Visual Foxpro Users Group
mbabcock@cpvfug.org
"Work smarter, not harder."