Link to home
Start Free TrialLog in
Avatar of debarton
debarton

asked on

How to default to next value for part of a field?

In my Access 97 database, I have a field Lab Number, of the format YYD/NNNN (e.g. 03D/1234). I want the form for entering new records only to allow the next lab number to be allocated, and to default to that number. For example, if the last sample was allocated 03D/1234, the next one must be 03D/1235. Lab Number is a text field with a validation rule: Like "##D/####"
Avatar of nico5038
nico5038
Flag of Netherlands image

Effectively you would need to split this field in the table into two fields:
YY
NNNN
The fixed "D" isn't really needed.
Showing the YYDNNNN code can be done using a stringing command in .g. a formfield like:
=YY & "D" & right("0000"&NNNN,4)

The "Right is to take care of possible leading zero's.

For a new Lab Number you can fill NNNN like:
me.NNNN=DMAX("NNNN","tblLab") + 1

Getting the idea ?

Nic;o)
Avatar of debarton
debarton

ASKER

Thanks, Nic;o)
I would certainly prefer not to have to split this field, as I would have to do a lot of re-writing of queries, forms etc., because the Lab Number field comes up everywhere.
David
Thinking about it some more, this wouldn't work anyway because the Lab Number starts at YYD/0001 each year, so we would end up with a whole load of duplicates if we took the YY out of the YYD/NNNN format.
David
ASKER CERTIFIED SOLUTION
Avatar of nico5038
nico5038
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial