"SDL20" <dy*******@gmai l.com> wrote in
news:11******** *************@i 40g2000cwc.goog legroups.com:
Right. It is a text box in a form. Each time I create a new
record I want the Employee ID ("Emp-n") to increase by one. I
can't figure out how to seperate the string, increase the
integer, and then concatenate it. Sorry, but I'm new to this.
Thanks for your help.
It's obvious you are new. If "Emp-" is a constant and will be
identical for each employee ID, you do not need (and a good
database designer would not want) to store that in the table,
because it wastes disk space, it complicates many operations,
and is absolutely easy to generate at the time you prepare a
report.
empid = "Emp-"+[employeeID] where [employeeID] is the fieldname
in the table for the number.
You would only need to store the "Emp-" part if it's subject to
change, like "XYZBoxesEm p-" "Firm2-" for different records.
Even then most database programmers would store that part as
text separately from the numeric portion and concatenate them
when needed [EMployeePrefix]+[EMployeeID]....
Now you can just store the number part, which makes the whole
thing a lot easier. as M.G. Foster said, you can define the
numeric part as an autonumber, and Access will always put a
unique, ascending but not necessarily consecutive number when
you add a new line
You could also write some visual basic code that looks up that
highest number already assigned and adds one to that, but that's
probably more complex than you need.
Anyways, to split a string you use the mid() function, to add
one you use the add operator +, and to concatenate two strings
you can use the + operator, or the & operator. the two
concatenation operators behave differently in the presence of
null values, but you don't need to worry about that for now.
As to returning the existing the maximum existing value, there
are several ways to go about this, the simplest is the dmax()
function, but as M.G. said that still doesn't guarantee
consecutive numbers.
Use the Help file F1 key to get info about the syntax for the
functions.
--
Bob Quintal
PA is y I've altered my email address.