Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Database Design / December 2004

Tip: Looking for answers? Try searching our database.

Yet Another Autonumber/Incremental Key Question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joe Williams - 07 Dec 2004 15:31 GMT
Ok, from the posts I have read I understand that I want to avoid using the
autonumber field for anything meaningful in access. So, after reviewing the
posts I have seen two distinct ways to accomplish a meaningful incremental
counter:

1) Create a field that represents a meningful number. On new records, do a
dmax() function, add 1 to it, and use that value as the value for the
incremental field.

2) Create the incremental field and also a seperate table that stores just
one value, which represents the last number used. On new records, look up
this new number, add one, then update the lookup table and use this new
value as the value for your incremental field.

So, here are my questions regarding this two methods:

1) Which method is better in a multi-user environment? I might have 4 or 5
people entering records at once and I don't want thier to be any issues with
record locking or getting the same number.

2) If I am using this incremental field, is there still a need for an
autonumber field? What are the advantages/disadvantages to keeping the
autonumber field in addition to the new incremental field?

Thanks

Joe
Allen Browne - 07 Dec 2004 16:38 GMT
The point of method 2 is that you LOCK the table containing the single
record while you increment it and write that number to the main table, and
then unlock it again. This locking guarantees that no two people can be
given the same number at the same time. Naturally, you have to code in a
fixed number of retries with random delays so as to handle the locking
conflicts.

Method 1 is not as safe. Your best shot is to use the last possible moment
to perform the DMax(), i.e. do it in Form_BeforeUpdate (the last event
immediately before the record is saved).

If you roll your own numeric primary key, there is no point at all in having
an autonumber field as well.

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

> Ok, from the posts I have read I understand that I want to avoid using the
> autonumber field for anything meaningful in access. So, after reviewing
[quoted text clipped - 23 lines]
>
> Joe
david epsom dot com dot au - 08 Dec 2004 00:04 GMT
How To Implement Multi-user Custom Counters:
http://support.microsoft.com/?kbid=240317
http://support.microsoft.com/kb/q191253/

"Microsoft Jet has a read-cache [and] a lazy-write mechanism ... in certain
situations that require high concurrency, they may create problems."

(david)

> Ok, from the posts I have read I understand that I want to avoid using the
> autonumber field for anything meaningful in access. So, after reviewing the
[quoted text clipped - 23 lines]
>
> Joe
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.