473,564 Members | 2,798 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Numerically incrementing a string

How do I incement a numeric portion in Access 2003? The field I want to
numerically
increment looks like this:

Emp-1
Emp-2
....
....
Emp-n

What would be the code to do this?
--SDL20

Feb 28 '06 #1
5 3056
SDL20 wrote:
How do I incement a numeric portion in Access 2003? The field I want to
numerically
increment looks like this:

Emp-1
Emp-2
...
...
Emp-n

What would be the code to do this?


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

for i = 1 to n
debug.print "Emp-" & i
next i

You might think about arrays:

const n = 25
dim strEnum(1 to n)

for i = 1 to n
strEnum(i) = "Emp-" & i
next i

--
MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRAOgloechKq OuFEgEQLLKQCg+y gyKB7joqS8Oxmho Vw8jGg5RkYAnRFV
iYlotTDUnr2CR4Q a1cVZ6lUB
=/lLH
-----END PGP SIGNATURE-----
Feb 28 '06 #2
"SDL20" <dy*******@gmai l.com> wrote in
news:11******** **************@ p10g2000cwp.goo glegroups.com:
How do I incement a numeric portion in Access 2003? The field
I want to numerically
increment looks like this:

Emp-1
Emp-2
...
...
Emp-n

What would be the code to do this?
--SDL20


It depends on where you want to use it, Is it in a query, in a
textbox , in the default value of a form?

First you need to separate the alphatic portion from the number.
Then you need to convert the numeric portion to an integer, then
you need to add one to that number. Then you need to format the
numeric part back to a string, and concatenate it to the
previously saved string portion.

For your simple example left(EMP_ID,4) & cint(mid(EMP_ID ,5)+1
This has no formatting nor error checking.
However, this will change the existing Employee ID, You didn't
specify, but I'll assume you want to
a) find the last created value of emp_id,
b) create a new record, and use the incremented emp_id for the
new record.

Code for that is more than you asked for.

Feb 28 '06 #3
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.

Mar 1 '06 #4
SDL20 wrote:
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.


What you're doing is complicated though it looks easy. You really
should be using an AutoNumber for the Employee ID if you just want to
have consecutive numbers. But, that has it pitfalls also - the numbers
can skip when a user decides to cancel a new record.

Ideally, you'd have a function that safely increments the employee ID
w/o interference from other users trying to add new employees. Search
Google groups (this group) for examples of how to do that (this subject
has been hashed over many times in this NG). The Access Developer's
Handbook has an example of how to do this.
--
MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
Oakland, CA (USA)
Mar 1 '06 #5
"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.
Mar 2 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5538
by: A.T. | last post by:
Am trying to sort the following file with the <xsl:sort> function, but can't get it to work properly. Would like the id column sorted according both alphabetically & numerically. (e.g. A-01, A-02, B-02). Currently the output, is a table display. XML DOCUMENT <root> <version> <id>A-01</id> <!-- other elements -removed for ease of...
7
3247
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) CType(local4, Short) = CType(src, Short)
7
2483
by: rockwell | last post by:
Hi groups i want to write a program ro numerically integrate an equation using the rectangle method,i know a little bit about the rectangle method but never used it abd dont quite really know how to program it.if you guys know how to do it, can you help me out. the equation looks like eq = ∫ sin(θ*Π) / cos(2*Π*θ) ,the integration is from...
8
661
by: Saputra | last post by:
Does anyone know how to sort a data view numerically? By default, when you sort a field from a table in a database, it sorts it in alpha-numerical order. In MS Access, sort is by alpha-numeric, that is, numbers sort from 1, 10 ,11, 1X, 2, 21, 2X, etc. I want VB.NET to sort a column in data view numerically, so it goes 1 - 9, 10 - 19, 20 -...
2
420
by: brian | last post by:
Hi, before coming to .NET, I utilized regular expressions mostly in JScript / JavaScript and also in my favorite text editor: TextPad (www.textpad.com) I don't know about JScript/JavaScript, but in TextPad's implementation of Regular Expressions, you can do a replacement expression like this: \i For every single non-overlapping match, it...
4
1821
by: masterpaladin38 | last post by:
I've been working on this problem for some time and I must say I'm stump. Any help would be appreciated. Basically what I'm trying to do is write the results of a loop to a new text file with every pass. For example the user chooses that the loop should run 10 times. I want to write the results of each pass of the loop to a text file by...
0
3360
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi all, I have a "connected" datagridview that uses a bindingsource/datatable to load the grid and update the user's modifications to the database. I have a column that is set in the database as varchar, but it is populated with values ranging from 1 to 49. It is not an option to change the column to integer in the database. When I...
3
1263
by: =?Utf-8?B?TWlrZSBL?= | last post by:
I have a Net 2.0 app in VB that has code like this: Dim intA as Integer Dim intB as Integer dim myList as new List(Of String) intA = 10 intB = 20 .... code to fill the list ....
15
27798
by: Peng Yu | last post by:
Hi, Suppose T is 'float' or 'double'. T x; x < 10 * std::numeric_limits<T>::epsilon(); I can use the above comparison to test if 'x' is numerically zero. But I'm wondering what should be a good multiplicative constant before
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7642
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.