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

Duplicate ..No please.....Help

Status
Not open for further replies.

ITphile

IS-IT--Management
Nov 27, 2001
51
0
0
IN
HI ALL,

I'm using Access 2000 as my DB with VB 6 as front end and there is a field by name ID in the DB, which will generate sequential number (like 1,2,3...) It works fine with one user and stand alone PC. When two of them are trying to save a record at the same time (over a network), it generates and saves the same ID (i.e 75 twice). I want to avoid this duplication.

Pl. help.

TIA

ITphile
 
You could set an index in the database to prevent duplicate entries, then code for the error rasied when a duplicate write is attempted.
or you could check that there is no record with that id before you write to the database. either way it is a good idea to use an index, preventing duplicates altogether.

Matt
 
Or try defining the ID column as an auto-incrementing field. You'll lose the sequence of the numbers, but you'll maintain uniqueness. Then you could use something like a timestamp field to determine the order in which records were added. That is:

Start a transaction

Add a new record - the ID column will automatically get a unique number. Then populate the timestamp field and the rest of the data. Save the record, committ the transaction and you're done.

/Cy
 
Autoincrement is OK if you don't need to keep track of the record. It sounds like the Record Id that is duplicating is the tracking key.

To make the ID work, you'll need to find a new way to categorize your records. For example a user id. After adding the record the ID will be the highest id value for that user.

Keep in mind, the id only has to make the record unique in the global set. Finding the record again can use other criteia to single it out.

Wil Mead
wmead@optonline.net

 
Can you set the ID as a primary key with autonumber in the database?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top