Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autoincrementing a value into a field 1

Status
Not open for further replies.

tripp2222

Technical User
Nov 30, 2004
32
US
I would like to increment a value into a field without using autoincrement in VPF or how to do it in SQL code, both sets of gave me two good options, but I would like to know how to do it without using either of those procedures. I am thinking it is possible through creating a record validation on the field or an expression. Also, I like to know how to close a database while adding in a record so that if two users are adding in a new record they do no lock the table or have duplicate records. I would really appreciate any help I can get, even if it is just pointing me into the direction to find more about what I would like to do with the databases.
 
Try the following function, it works for me.

FUNCTION Genidnum

PARAMETERS tTablename

SET REPROCESS TO 5 SECONDS 5

lnSelect = SELECT() && Store alias number to variable
SELECT Systemids
SET EXACT ON

LOCATE FOR UPPER (ALLTRIM (tTablename))=UPPER (ALLTRIM (Systemids.tablename))
IF NOT FOUND ()
APPEND BLANK
LOCK()
REPLACE Systemids.tablename WITH tTablename
lIDValue=Systemids.idvalue
lIDValue=lIDValue+1
REPLACE Systemids.idvalue WITH lIDValue IN Systemids
UNLOCK IN Systemids
ELSE
LOCK()
lIDValue=Systemids.idvalue
lIDValue=lIDValue+1
REPLACE Systemids.idvalue WITH lIDValue IN Systemids
UNLOCK IN Systemids
ENDIF

SELECT (lnSelect) && Reset alias to as was before the code started.
RETURN Systemids.IDValue
SET EXACT OFF
ENDFUNC

G K Bray MCSE(Win2k) Trainee Programmer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top