Lynn Trapp was zeer hard aan het denken :
Give this a try in a query.
Left([Firstname],2) & Left([Lastname],2) & "-" & [YourAutoNumberField]
--
Lynn Trapp
MS Access MVP
www.ltcomputerdesigns.com
Access Security:
www.ltcomputerdesigns.com/Security.htm
Doug, I agree with you. I am not trying to combine these
three fields. I just wanted to know, if it was possible
to achieve that and how. I have an entry form where new
records are added, so I was trying to see if it was
possible to create the ID field by using the first two
characters of the FirstName or LastName fields or both
plus some autonumber. For example for Adam Smith the ID
would be AD-01 or ADSM-01, where the numeric part would be
an autonumber. Do you know how to do this? I would really
appreciate your help.
And what exactly would be the base of this autonumber? Each combination
it's own number like AS01, AS02, LT01, AS03. I can imagine some
combinations would go over the 99 count...
But anyway, you should build a query retrieving the highest used number
from the letter-combination
SELECT TOP 1 Right(<IDfield>,2) FROM <table> WHERE LEFT( <idField>,2) =
Left([Firstname],1) & Left([Lastname],1) ORDER BY <IDField> DESC
Now you should have the highest number in your recordset. Add one and
build the new key. If the recordset is empty, there wasn't any previous
entry with those letters.
You could probably also use a count statement since that gives you the
total used.
Problems? Yes, to name a few :
- More then 99 entries for a lettercombination
- Deleted entries (AS02 is deleted; this query won't solve that
problem, you'll have to use code for retrieving that one)
- Two (or more) users running this procedure at the same time could end
up with the same ID, so you must check to see if your ID is free and,
preferably, reserve it by adding it to the database as soon as possible