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 / Modules / DAO / VBA / September 2005

Tip: Looking for answers? Try searching our database.

Creating an unique ID number in sequential order

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
nanarado - 23 Sep 2005 17:55 GMT
After creating a very simplistic database, I recently realized that using an
autonumber as a refence for records is not a good thing.  My database was
created to manage a filing system, so it is very important for it to be able
to number each record in the order that it is entered in the system.  When
records are deleted, the deleted number should be reassigned to the following
new record.

I currently have 100 records in place.

I have seen a couple of fixes for this, but I am a beginner user and need
more specific instructions.  If there is a need to code, please let me know
specifically where the code is to be placed.

Please Help!
Tim Ferguson - 23 Sep 2005 18:30 GMT
> After creating a very simplistic database, I recently realized that
> using an autonumber as a refence for records is not a good thing.  

Arguable... :-)

> My
> database was created to manage a filing system, so it is very
> important for it to be able to number each record in the order that it
> is entered in the system.

In that case, it sounds like an autonumber is indeed a poor choice.

> When records are deleted, the deleted
> number should be reassigned to the following new record.

That is actually a really poor decision -- not in computing terms but as
sound record-keeping practice. Do you have really strong methods for
tracing _everyone_ and _everything_ and _everywhere_ that may have
collected the used number before it was deleted and reallocated?

Your best solution in Access depends on your actual business practice.

The simplest thing is just to pick up the next folder off the shelf and
type its number into the data entry form. Simple and faultless (given
suitable validation and error checking, of course).

The fancy version requires some kind of algorithm to work out the next
number to be allocated and for access to produce it, so you can write the
number on the folder. This always requires some coding; it can be simple
or complex depending on your needs. The most demanding situation is in a
multi-user database where more than one client may be trying to insert
records at the same time.

Hope that helps

Tim F
nanarado - 23 Sep 2005 18:44 GMT
Tim:

I realize this was a poor decision, I had very limited knoweldge of the
autonumber's limitations.

This is not a very complicated database (no relationships), however there
will be multiple in-office users.  I was hoping that someone could just let
me know what code to use to automatically increase the file number by 1.  I
also do not want this field to be entered by the user or edited by the user.  
I don't mind deleting all records and begining again if necessary.

If you do reply with code, please let me know where I am to enter the
code... as a macro or VB etc.

> > After creating a very simplistic database, I recently realized that
> > using an autonumber as a refence for records is not a good thing.  
[quoted text clipped - 32 lines]
>
> Tim F
Tim Ferguson - 24 Sep 2005 19:36 GMT
> however there
> will be multiple in-office users.

There are lots of possible solutions: try googling for something "Access
custom autonumbers multi-user".

FWIW, this is what I do:

 ' this is a partial command!
 jetSQLShort = "INSERT INTO MyTable(RequiredField, IDNum) " & _
   "VALUES( ""Default"", "

 ' need to error trap this, obviously
 dwInsertNumber = DMax("IDNum", "MyTable") + 1

 ' now find a new number
 Do While True
   ' try to insert it but trap any error
   On Error Resume Next
   db.Execute jetSQLShort & dwInsertNumbr * ")", dbFailOnError

   ' if that worked, then we've finished already
   If err.number = 0 then exit do

   ' if we are still here, then someone else already used
   ' that number. Need to screen for other errors too, like
   ' locked table etc etc

   ' restore normal runtime error handling (nb what about
   ' integer overflow..?
   On Error Goto 0
   ' and look at next number
   dwInsertNumber = dwInsertNumber + 1

 Loop

 ' on exit dwInsertNumber holds the correctly inserted number

Hope that helps

Tim F
 
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.