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

Posted on 2003-03-22
Medium Priority
Last Modified: 2012-06-21
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/####"
Question by:debarton
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 54

Expert Comment

ID: 8186263
Effectively you would need to split this field in the table into two fields:
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 ?


Author Comment

ID: 8193758
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.

Author Comment

ID: 8193808
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.
LVL 54

Accepted Solution

nico5038 earned 200 total points
ID: 8194055
Drop me a line in my nico5038 mailbox "at" yahoo.com asking for the "increment" sample.

This shows a (numeric) Year/Sequence number.

Problem with the internal "D" is leading to my "split" comment.
Even using internally YYNNNN and creating the YYDNNNN from stringing is an option. The "D" is just a fixed value as far as I can see.

Using separate fields is always possible as you can use a SELECT MAX(NNNN) FROM tblX WHERE YY = "03";


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question