I see. I didn't try it on a continuous form. This leads me to a related
sort of question. I am similarly assigning a number (although in a single
form), but am doing so in the OnCurrent event. This lets the user see the
number before entering other information, which is necessary for several
reasons. One of these reasons is that after completing a section of the form
the user will use a command button to send an e-mail to the next person
advising them that the form needs attention.
To explain further, the report is a recommendation. The person who makes
the recommendation can click a button to send an e-mail to the manager
informing him that RPT 05-01 has been filed. 05-01 is the DMax number, but
is not the primary key because I feared difficulty in the event that two
people attempt to make a recommendation at the same time. It is not very
likely, but is certainly possible. The manager would then assign somebody to
respond. After the recommendation has been made and the user exits (and thus
saves the record) any further action will not affect the number.
Perhaps the button to send the e-mail, or maybe the After Update event for
the recommendation text box, could contain code that saves the record or
offers the opportunity to undo? It would have to contain some sort of
message in case the number they thought was assigned needs to change. I need
to make this work with as little user intervention and training as is
possible. It needs to be self-explanatory, if for no other reason than that
some people may only use the database once or twice a year, and cannot be
expected to remember details of how to work with it.
Rick Brandt said:
Since the OP has specified that he is using a tabular (continuous) form,
then using DMax as a default value will not work. If you try it you will
see the following behavior...
Open form with 1 existing row, ID = 1. Below that the "new row" position
will have the default value of 2 for ID (so far so good). As soon as the
user dirties the new row another new row will appear beneath it and since
the record being worked on is not yet part of the saved recordset the ID
will also default to 2 in the "new new" row. When he dirties the new new
row yet another new row will appear with a default ID of 3. Of course when
the second new row is saved a duplicate key error will be raised forcing the
user to manually change the value to a 3 and the problem repeats itself for
all new insertions.
On a continuous form the only DMax() + 1 strategy that will work is to
assign the value in the form's BeforeUpdate event. Even on a single view
form using DMax() + 1 as a default or assigning it in any other form event
cannot work reliably in a multi-user environment because two users entering
records at the same time will be grabbing the same values and colliding with
each other.
Try this for the default value of the control (text box):
=Nz(DMax("[FieldName]","TableName"))+1
To format it as "001", "002", etc. you could add 000 to the Format
property for the control.
Buthy said:
Hi,
I created tabular form that has serial number column. I need to make
it as serial number generated. For example first row will have #1,
and then for second row will have #2.
Please help. Thank You.