Dlast

F

Frank Dulk

Hello personal, I have one doubts that would help me plenty to find a
solution to facilitate my cadaster.
I have a form I continue and in him I have to type numbers of meters in
sequence, it would like to configure the field of the I number of the meter
so that the Standard Value always roots the Last Registration adding +1, I
explain that is the last and not the largest numbers.
 
D

Douglas J. Steele

DLast is actually a meaningless concept, since relational database theory
says that rows in tables can be in any order. Instead, use DMin or DMax
(whichever is more appropriate)
 
D

Dirk Goldgar

Frank Dulk said:
Hello personal, I have one doubts that would help me plenty to find a
solution to facilitate my cadaster.
I have a form I continue and in him I have to type numbers of meters
in sequence, it would like to configure the field of the I number of
the meter so that the Standard Value always roots the Last
Registration adding +1, I explain that is the last and not the
largest numbers.

Hi, Slim!

As usual, your question was not very well translated by your translation
software. If I understand it, you are working with a continuous form
and you want the default value of each new record's [MeterNumber] field
to be 1 + the [MeterNumber] field of the last record entered.

This is easy to do within an editing session, because you can set the
DefaultValue property of the [MeterNumber] control in the form's
AfterUpdate event. However, if you want this to work even if you close
the form, then reopen it and add a new record, you need some way to
identify which is the "last record". If your form's recordsource table
has a consecutive autonumber field, you can use the record with the
highest value in that field. But that's not altogether reliable.
Better would be to have a LastModfied field that is always set to
ow() -- the current date/time -- when a record is saved. Then you can
assume that the record with the maximum value in that field is the last
record that was modified -- at least, you can assume that if there's no
reasonable chance that two users will add records to the database at
exactly the same time.

Taking this approach, you might have an event procedure for the form's
Current event something like this:

'----- start of example code -----
Private Sub Form_Current()

Me!MeterNumber.DefaultValue = _
1 + _
DLookup("MeterNumber", "MyTableName", _
"LastModified = DMax('LastModified', 'MyTableName')")

End Sub

'----- end of example code -----

Of course, you would have to replace "MyTableName" with the name of the
table on which your form is based, and replace the field names
"MeterNumber" and "LastModified" with your field names.
 
Top