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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating an unique ID field in a table

Status
Not open for further replies.

michellq

Programmer
Nov 10, 2000
15
NL
Dear VFP users,

I am creating a field what needs unique numbers.
In the table designer in VFP 5.0a there is no possibillity tot create an autonumber field.

In the table designer I do see a possibility to create a default value. You can als place a function, for example: NewID().
Can someone tell me the code to fill in automatic a unique value in this field??

Nice regards,

Michelle
 
1. Have a index on the unique field.
[tt]
set order to unidueid
goto bottom
do while .t.
if rlock()
m.uniqueid = alltrim(str(val(m.uniqueid)+1))
unlock
append blank
replace uniqueid with m.uniqueid
exit
endif
enddo

2. Have an external table NEXTID.DBF with one record/field in it called ID
select 0
lcerror = on("ERROR")
on error **
do while .t.
use NEXTID EXCLU
if _error < 1
replace NEXTID.ID with NEXTID.ID+1
M.UNIQUEID = alltrim(str(int(NEXTID.ID)))
use
exit
endif
enddo
on error &lcError
[/tt]

David W. Grewe
Dave@internationalbid.com
ICQ VFP ActiveList #46145644
 
Opps, I forgot #3
see FAQ 3a in the forum.

David W. Grewe
Dave@internationalbid.com
ICQ VFP ActiveList #46145644
 
Hello dgrewe,

Thank you very much for your answer.

Michelle.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top