The Count won't work, because if you delete Client A8, that could would give
you A10 again even though you already have an A10.
Why not just use an autonumber? Saves all the hassles, and solves the
multi-user issues. For example, if you have 2 users adding new clients
starting with A at once, your own code is likely to give them the same key.
To solve that properly means writing code to handling the locking issues,
and introduce random delays and retries to overcome the clash. The
AutoNumber solves this for you.
If you really want to use your code your own, you need to use codes like
A000001 so you can quickly identify the maximum value assigned to the prefix
letter, increment it, and create the new key. Use the BeforeUpdate event
procedure of your form, since that is the last possible moment before the
record is saved.
The kind of thing you will want is:
Left([ClientName], 1) & Format(Val(Nz(DMax("ClientID", "Clients" , "ClientID
Like """ & Left([ClientName], 1) & "*"""), 0)) + 1, "000000")
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Rupert Street" <ja**********@yahoo.com.au> wrote in message
news:3a*************************@posting.google.co m...
Hi
I am new at setting up a database and requesting info from groups so
please excuse any mistakes that I inadvertently make.
I have set up a table with client info including a ClientID. The
ClientID is made up of the first letter of the client name plus a
sequential number eg A10 (Adam Bros P/L) J03 (Jolly, TJ & Sons) and I
want it calculated for me so as to minimise mistakes.
I set up a form to enter the client info & included a textbox (Control
Source)=Left$([Client],1). I then figured if I ran a query
automatically with the SQL statement SELECT Count ([ClientID]) AS
NewNumber FROM Clients WHERE [ClientID] Like 'A??'; that would work
out how many clients started with that letter then the ClientID
control would be =Left$([Client],1) & Sum([Query1]![NewNumber]+1).
What I don't know how to do is run the query from the form
automatically, how to set up a variable to collect the letter from the
textbox and if I am doing it correctly in the first place.