Custom Sequential Numbering

K

Keith Wilby

John W. Vinson said:
Is that correct, Arvin? IME if you even *start* adding a new record
manually
(on a form, or directly in a table), an autonumber is generated; if you
hit
<ESC> or otherwise cancel the addition before it's saved to disk, the
autonumber gets used up and skipped... leaving a gap.

Has this changed without my noticing?

I think that Arvin is recommending this method with the caveat that the user
may create gaps by either deletion or by discarding a new but unsaved
record. To me that does not satisfy the OP's requirement. Even if you
disallow deletions you'll never stop users from creating new records and
then changing their minds, and why should you?

Keith.
 
A

Arvin Meyer [MVP]

John W. Vinson said:
Is that correct, Arvin? IME if you even *start* adding a new record
manually
(on a form, or directly in a table), an autonumber is generated; if you
hit
<ESC> or otherwise cancel the addition before it's saved to disk, the
autonumber gets used up and skipped... leaving a gap.

Has this changed without my noticing?

Is hitting escape, not akin to deleting a record? With an Access form, or
any bound form, the first character typed creates a record, does it not?
<ESC> is what one would do to delete that record.

I think we are saying the same thing in different ways. Autonumbers cannot
be reused, whether the record is started or deleted. Once used, it's gone.
 
A

Arvin Meyer [MVP]

IMHO dirtying a record but not saving it is not the same as deleting a
saved one, and users are going to wonder why the sequence is broken when
they haven't deleted anything. In fact, they're not just going to wonder
but they're going to complain quite loudly!

Dirtying a record has the identical effect as deleting it. To use the paper
analogy, once a restaurant check has been written on, it's dirtied, you can:
1. Throw it away
2. Leave it the way it is.
3. Change the data (to some degree)

In all of those cases, the number is used. Only the first leaves a visible
gap.
I also seem to remember reading somewhere, although I can't provide any
evidence, that even if you don't force Access to discard an AutoNumber, it
is still possible to have a broken sequence in an incremental AutoNumber.

I don't think so except for the now fixed bug that allowed autonumbers to
attempt reuse.
FWIW I don't allow deletions in systems that require sequential numbering,
rather I give the option to mark a record as "deleted" and then query
accordingly.

Good move.
 
G

Gina Whipp

Keith,

This might be what you are remembering...

***QUOTE

Even if you could, autonumbers are not truely incremental. If you need
something at is incremental with no possibility of a break in the numbering,
do NOT use autonumbers. For example if you start a new record that has an
autonumber field, then change your mind, that autonumber is 'burned' and you
will have a gap. Sometimes Access will pull out an out of sequence
autonumber, including even negative numbers, for no apparent reason even
when set to incremental.

Your best bet is to do a DMax of the primary key field in the table and add
1 to it just before saving the record. For this you need to use a form and
hope that more than one person is not inputting a new record at the same
time.

Other DBMSs have things like Sequences that will truely produce an
incremental number when needed.
--
Jerry Whittle, Microsoft Access MVP
Light. Strong. Cheap. Pick two. Keith Bontrager - Bicycle Builder.

***END QUOTE

--
Gina Whipp
2010 Microsoft MVP (Access)

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm
 
K

Keith Wilby

Arvin Meyer said:
Dirtying a record has the identical effect as deleting it.

I think we're talking at cross purposes; you're talking technical and I'm
talking user-interface.

From the user's viewpoint they are two distinct processes. You could
possibly train a user to never delete a record, you could even deny them
that functionality, but unless you design it out there is always the dreaded
ESC key method of their changing their mind about creating the new record.
I'm not challenging your logic from a technical POV but I am challenging the
suitability of AutoNumbers for this purpose given the risk of user
interference (for want of a better phrase) and for the reason cited by Jerry
Whittle, kindly re-posted by Gina.
 
J

John W. Vinson

Is hitting escape, not akin to deleting a record? With an Access form, or
any bound form, the first character typed creates a record, does it not?
<ESC> is what one would do to delete that record.

Well... the record is not actually written into the table until the form is
closed, you move to a different record, etc. - things that trigger the Update
events. There's a record but it's not a real record in the table. But yes,
you're deleting the (unsaved, incipient) record.
I think we are saying the same thing in different ways. Autonumbers cannot
be reused, whether the record is started or deleted. Once used, it's gone.

In that we're in agreement, and my take is that this fact makes autonumbers
completely unsuitable if sequential gapless numbers are required.
 
K

KenSheridan via AccessMonster.com

Keith:

While I'm essentially in your camp on this one, in that I don't think one can
really say that the abortion of the insertion of a new row into a table and
the deletion of an existing row are the same, either technically or
conceptually, its worth pointing out that on a pragmatic level it is actually
very difficult to cater for Tara's requirements fully whichever approach is
adopted.

The problem issue is the abortion of a new row without abandoning the number.
An autonumber fails on this count of course. Roger's doesn't but fails to
meet Tara's need for the number to be known to the user while entering the
other data for the row. Your solution covers this, but means allowing Nulls
in all non-key columns, or giving each a default value, both of which I'd be
unhappy about.

Mine acts like an autonumber in that an aborted row means the number is lost,
though can be 'reseeded' if no other user has begun to insert a row. While
it wouldn't be difficult to handle this if only one user is inserting a new
row, the whole raison d'être of the more complex approach rather than a
simple DMax call is to cater for simultaneous multiple inserts of course. I
could cater for this in mine by excluding other users from the external
database, in which the number is stored, from the time one user begins to
insert a row until they either save or abandon it, but that would be unduly
restrictive to my mind. The other option of restoring the externally stored
number to the value it had before a user began to insert a row is not
feasible as one or more users might well have inserted rows in the meantime
and thus used the subsequent numbers. The only other option which occurs to
me would be for the number generation routine to re-use any gaps which had
been created in the sequence, which would be simple to do by storing all used
numbers in the external database rather than just the latest one, but that
loses the sequentiality of the number generation process, so can't be
considered a serious contender. I don't think there is a satisfactory
solution which totally covers all of Tara's requirements in fact; the
inherent paradox is just too fundamental as far as I can see. I'd be
delighted to be corrected, though!

Ken Sheridan
Stafford, England
 
D

David W. Fenton

Is hitting escape, not akin to deleting a record?

No, because the record was never saved. But the Autonumber seed gets
incremented even if the record was never saved.
 
D

David W. Fenton

The problem issue is the abortion of a new row without abandoning
the number.

If you use an unbound field to collect the data to create the new
record, it will be "abandonable" without touching the Autonumber
value.

Indeed, this is how most of my apps do their NEW RECORD creation for
entities of any level of complexity.
 
K

KenSheridan via AccessMonster.com

That still does not satisfy Tara's requirement of making the number available
to the user during the process of data entry. That this precludes aborting
the insertion of a new row while maintaining sequentiality is the fundamental
paradox here which is impossible to obviate satisfactorily as far as I can
see. If you take that requirement out of the equation then Roger's method
handles things very simply and reliably.

Ken Sheridan
Stafford, England
 
L

Larry Linson

Arvin Meyer said:
I don't think so except for the now fixed bug that allowed autonumbers to
attempt reuse.

Arvin, in either Access 2.0 or 97, I experienced some instances of Access
Autonumbers skipping hundreds or thousands of numbers. I was the only one
working on the databases at the time, and I know that I had not done any of
the "normal causes" hundreds or thousands of times, nor had there been any
delete queries executed. Fortunately, I knew by that time not to rely on
Autonumbers being monotonically increasing, so it was not a problem to me.

And, because it was not a problem for me, I didn't bother to try to analyze
the cause other than what I said in the preceding paragraph.

Larry Linson
Microsoft Office Access MVP
 
A

Arvin Meyer [MVP]

In that we're in agreement, and my take is that this fact makes
autonumbers
completely unsuitable if sequential gapless numbers are required.

The original request did not mention gapless as a requirement. In any case,
and system that allows deletions cannot, by definition, be guaranteed
gapless.
 
A

Arvin Meyer [MVP]

Roger's last post makes the most sense. If you are taking a number from a
paper, you do not need to generate it.

Further, any scheme for multi-users, must save the number immediately after
generation, or multiple users can conflict. The only way a custom generated
number can not have the same problem as the autonumber is if it is generated
as the last event on the form ie in the form's afterupdate event.
 
L

Larry Linson

Roger Carlson said:
I know there are customers who believe they "need"
sequential numbering for some reason, but I always
try to dissuade them. Sometimes it works
sometimes it doesn't, but I try.

Long ago, but not so very far away, in the days of Access 2.0, I was doing
some work for a client on the prototype of an application that presumably
was going to be developed further to cover the workflow in their entire
production process. The "little old* lady accountant" who was one of the
ones who had to approve just about had a fit of apoplexy when she saw
missing numbers and it was explained why.

* not as old then as I am now, I suspect, but a real,
old-time, green eyeshade and sleeve-garters
bookkeeper type person

That's not one of those cases where you want to have a logical discussion to
prove the client's approver wrong. It was simple to correct... slight logic
change, DMAX out of the bag of tricks, and everybody was happy. Except, in
the longer term, the contract broker for whom I was working when they found
out they weren't "in with" the IT manager as they had thought.

He just up and took another job somewhere else, didn't even bother to call
the sales person for the contract broker, and he'd been the executive
sponsor of this particular application. The new IT manager decided to move
everything from client-server to IBM AS-400.

Bye, bye, development contract.

Larry Linson
Microsoft Office Access MVP
 
J

John W. Vinson

He just up and took another job somewhere else, didn't even bother to call
the sales person for the contract broker, and he'd been the executive
sponsor of this particular application. The new IT manager decided to move
everything from client-server to IBM AS-400.

Bye, bye, development contract.

.... and bye, bye, performance and responsiveness from their database and their
developer/IT staff. Sigh.
 
T

Tara Metzger

Well, leave it to me to have the scenario that doesn't have a perfect solution. :) You have all been extremely helpful! Looks like I'll have to come up with a solution based upon the wonderful information you have given me and possibly some of my own creativeness. The former I'm sure will be useful, the latter...we'll see :)
Thank you again for all the dialogue! It is a tremendous help! I'll post a reply telling you what I've been able to come up with.

Tara



John W. Vinson wrote:

wrote:...
21-Jan-10

wrote

.... and bye, bye, performance and responsiveness from their database and thei
developer/IT staff. Sigh
-

John W. Vinson [MVP]

Previous Posts In This Thread:


Submitted via EggHeadCafe - Software Developer Portal of Choice
Title Case Proper Names
http://www.eggheadcafe.com/tutorial...07f-c70a4fb08b05/title-case-proper-names.aspx
 
D

David W. Fenton

That still does not satisfy Tara's requirement of making the
number available to the user during the process of data entry.

I fail to see the issue. Just because you collect the data to create
the record in an unbound form does not mean you don't show the user
the sequence number once you've created the full record from the
data entered in the unbound form.
That this precludes aborting
the insertion of a new row while maintaining sequentiality is the
fundamental paradox here which is impossible to obviate
satisfactorily as far as I can see. If you take that requirement
out of the equation then Roger's method handles things very simply
and reliably.

I don't understand why it wouldn't work. The requirements in the
original post are:

1. Each time a Registration # is entered it is to increase by 1 and
it needs to show the user the Registration # they are currently
working on (in a form).

2. Complicating matters is the possibility of multiple users
entering data at the same time.

Using an Autonumber that is created only after the initial
information is entered in the unbound ADD NEW form insures that you
don't have any abandoned sequence numbers.

Once the data for the stub record is collected, you insert the new
record and load the new record in your full data editing form.
Autonumbers are quite immune to multi-user problems (they weren't
before Jet 3.x), and since you're inserting you record via a SQL
INSERT, the amount of time the back end table is locked is as tiny
as possible with Jet.

Now, if you read #1 as saying that the user needs to see the next
registration number *before* the record is created, that's
different. I don't read #1 as implying that at all, and I also don't
see why it should be a requirement.

Certainly the way I do this is that I use the unbound form to nudge
the user into avoiding entering duplicates, since after entering the
stub data, I look up all records with similar data and present them
in a subform as possible duplicates (and providing a mechanism to
abandon the add and go to the correct existing record instead). That
list of possible dupes could display the registration numbers for
the existing records.

But the details would depend on what the requirements of the
application are. I don't see any reason that a lot of cases where a
sequence is needed could not be kept as clean as possible (i.e., no
lost Autonumbers because the record was abandoned before it was ever
saved) with the unbound ADD NEW RECORD form.
 
D

David W. Fenton

[nothing I'm addressing]

I just wanted to say that in my newsreader, this message was
displayed with the header:

Re: I can't agree with you more about the necessity of <Arvin
Meyer [MVP]>

It made me grin and nod in agreement.
 
Top