Re: Generating Unique Numbers on a Form with Multi-users



Hi Rick.

"Rick Brandt" <rickbrandt2@xxxxxxxxxxx> wrote in message
news:OFvhh.23942$wc5.17767@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
"Keith Wilby" <here@xxxxxxxxx> wrote in message
news:45864dc6$1_1@xxxxxxxxxxxxxxxxxxxxxxxxx
"Douglas J. Steele" <NOSPAM_djsteele@xxxxxxxxxxxxxxxxx> wrote in message
news:O$dZngFIHHA.4896@xxxxxxxxxxxxxxxxxxxxxxx
Not sure that's appropriate in a multi-user environment, Keith. While
the odds are very low, it's possible two users may grab the same value
that way.

Works fine for me Doug, but I always do a refresh immediately and don't
allow deletions (provide a "deleted record" flag instead).

What does refreshing have to do with it? If a user navigates to the new
record position he can let the form sit like that indefinitely before he
actually enters and saves a record.

I think you may have misunderstood. I have Allow Additions set to False and
the following code in the button's click event.

Private Sub cmdNext_Click()

Me.txtUniqueNo.DefaultValue = Nz(DMax("MyField", "qryMyQuery")) + 1
Me.AllowAdditions = True
DoCmd.GoToRecord , , acNewRec
Me.AllowAdditions = False

End Sub

I haven't worked on this app in a while but IIRC "Me.AllowAdditions = False"
has the effect of saving the record, rather like a Me.Refresh.

During that interval numerous other users will have already used the
default number on his form as well as many higher ones. He is virtually
guaranteed to get an error unless your idea of "multi-user" is very
conservative.

Not to mention that assigning this value with the DefaultValue property
doesn't work at all on a continuous form (even in a single user app).


I think that two or more users clicking the button at *exactly* the same
instant is a remote possibility, so remote that the risk is negligible. It
hasn't happened for this particular app in the 10 years it's been in use.

Regards,
Keith.


.