Unique ID's in an access database using vb.net

Hi,

Like in MSSQL you can create new unique ID's using newID() is there a way to do this in an access database.

Many Thanks
Lee
ljhodgettAsked:
Who is Participating?
 
mbizupCommented:
You can define a field as Autonumber in the tables design.
0
 
Rey Obrero (Capricorn1)Commented:
in vba, you can use

currentdb.Execute "Alter table tableName add column newID counter"
0
 
mbizupCommented:
Clarifying... If you define the field as Autonumber inside Access, any new records created through your VB.Net interface will automatically be assigned a unique number.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
ljhodgettAuthor Commented:
With Autonumber isn't this an incrementing number for the table and not for the database as in MSSQL.

Best Regards
Lee
0
 
mbizupCommented:
Yes.  My understanding of the newID() function is that it will return a totally unique alpha-numeric "number", and it will never be repeated within that database (or on that computer?).    AFAIK, Access has nothing like that.  The closest is the Autonumber, which  is unique for that table.
0
 
ragoranCommented:
You could simulate newID() behavior with a dedicated table that contains just an autonumber field.

When you need a newID:
1- Append a row in the table
2- Query max(IDcolumn) to fetch the number inserted
3- Delete all records where IDColumn < fetched number (no need to keep more records than the last one)

If you run in a multiuser environment, encapsulate this logic in a transaction.


0
 
mbizupCommented:
@ ragoran:
That's a great workaround!
0
 
ragoranCommented:
@mbizup:

thanks for the good word
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.