Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

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/####"
0
debarton
Asked:
debarton
  • 2
  • 2
1 Solution
 
nico5038Commented:
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)
0
 
debartonAuthor Commented:
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
0
 
debartonAuthor Commented:
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
0
 
nico5038Commented:
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";

Nic;o)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now