perception = reality
This is also why lately I have taken to keeping forms as free of code
as
possible. if there is any realy processing at all, I create a standard
module and do as much of the code there as possible. To keep it all
straight
for my 4K brain, I name the module the same as the form:
frmBuzFoo
modBuzFoo
:
Ah, perceptions! I'll have to keep that in mind.
Yes, the DMax will take the same length of time to execute
regardless
of
where it is located in the form. The concept is user perception.
If
it
take
a few seconds for a form to appear, the user preceives the
applcation
to
be
slow. If the form pops right up, then starts looking in the
database,
the
user preceives the application is fast. The user will take a second
or
two
to react once the form is presented, so they don't notice the lag.
My using MAX was a typo. MAX is an SQL agregate function.... oops!.
As to moving to the Child record, you are correct.
:
Always good to see what you have to say, Klatuu. Wouldn't the main
record
be saved automatically when moving to a child record? In that case
there
couldn't be any child records if there is a duplicate number error
in
the
main form. But I agree that I got ahead of things there.
One of the reasons I suggested Roger's example is that it not only
provides
a simple means of incrementing a number, it provides multi-user
error
handling. I had not known that the Max function in a default
property
would
bog down the database if there are a lot of records, so that's good
to
know.
There isn't as big a performance hit with the function in an Event?
By
the
way, Roger's example uses DMax; as an aside I don't quite get the
distinction between Max and DMax in this case.
If the user does not need to see the number from the beginning it
could
be
assigned in the form's Before Update event. That should guard
against
most
errors, but error handling is a good idea anyhow. But again,
that's
running
out ahead of the immediate question.
Your point is valid, Bruce; however, the OP is probably not ready
to
address
that issue, yet. I would suggest we get it working, than cover
that
ground.
Basically, there are two approaches to dealing with this issue in
a
multi
user environment. One is to create a record immediately to
reserve
the
number. The problem with that approach is that if the user
cancels
the
entry, there is a gap in the numbering. The other is to use
error
handling
to warn the user, try a new number, and make sure any child
records
are
updated correctly.
This is certainly a confusing issue for someone who is not yet a
seasoned
database developer. So, my point is that although your concern
is
valid
and
important, the primary goal at this time is to get a working
model,
then
deal
with the other issues.
:
I expect you will pay no more attention to this than to my
previous
posting,
but if you have a multi-user environment you will need to take
steps
to
guard against errors if two users enter a record at the same
time.
Thanks! That sounds like just what I want it to do. I'm
confused
about
which values to enter into the field properties though. I'm
kind
of
new
at
this and not entirely familiar with codes or syntax or
expressions
and
the
like. I've changed the field in the database from Autonumber
to
a
text
field. Can I assume that in order to have the
Work_Order_Number
field
autopopulate that I should put an expression in the "default
value"
property?
And if so would the expression then be =DMax[("table
name","field
name")]+1
? (the table name is "2006 Work Orders" and the field
name
is
"Work
Order Number"
--
Ridnaway
:
If the Data Entry property of the form is set to Yes in
design
view,
then
it
is a data entry form. Data entry forms are for entering new
data.
They
always start off blank, but without acctually creating a
record.
If you form opens up with the first record in the recordset
showing,
then
it
is not a data entry form. If this is the case and your
control
for
the
autonumber field is bound to the autonumber field, then when
you
create a
new
record, the number should show up.
I am a little lost on a solution because I never use
autonumbers
as
data.
IMHO, users should never see them. They are intended to be
used
for
establishing key values for table relationships. One thing
to
be
aware
of is
that you will experience gaps in the numbering sequence. If
a
user
begins to
create a record, the cancels it, the number assigned is not
reused.
Here is a method I use if I need a sequentially numbered
field.
It
is
flexible enought it can be used even within a field that has
other
repeating
values. For example, in once case, a user wanted a unique
number
that
was
Year, Month, and an incrementing number as in 2006040001,
2006040002,
2006050001, etc
But for example purposes, I will show you the basic way to do
this.
Use
the
form's current event:
If Me.NewRecord then
Me.txtOrderNumber = Max("[OrderNumber]",
"tblOrderHeader") +
1
End If
This emulates auto numbering, but leaves no gaps unless you
delete
a
record.
What happens is when you add a new record to your table, it
looks
for
the
highest value in the field you identify and adds 1 to it and
puts
it
in
the
text box for the order number.
:
It is a form. I'm not sure how to identify it as a data
entry
form...didn't
know there was a difference. However, even if I begin
entering
data
in
the
next field it will not populate the autonumber. Thanks for
your
help.
Any
other thoughts?
--
Ridnaway
:
If your form is defined as a Data Entry form, then it is
for
adding
new
records and comes up will all controls empty. That is
because
a
record is
not actually created until you start entering data.
:
I am using a form to populate my database of work
orders.
I
have a
text box
on the form named "Work Order Number" and I want it to
automatically place
the next sequential number into this field upon opening
the
form.
The field
is my table is named Work_Order_Number and is set at
autonumber
but
it isn't
placing the number onto the form when opened. What
have I
not
done?