Automatic # generation

  • Thread starter Thread starter jmunderpar
  • Start date Start date
J

jmunderpar

I am attempting to write an incrementing, automatic number
routine that is based on a text, not numeric, field. The
numbers contain a letter at either the beginning or end of
them. Any help would be very much appreciated...Thanks!!
 
The way you would do this is by using the ASC function.
& then the CHR function to write back to Text

See Help...

ASC Function

Returns an Integer representing the character code
corresponding to the first letter in a string.

So for example...

ASC("A") would return 65

So you can assign it to a variable & then increment it.

Num = ASC(WhatEverChararcter)
Num = Num + 1
NewCharacter = CHR(Num) 'now will be "B"


If the text you are using has multiple characters then
you can use String functions like MID to get the
character you want.

Example..

Value = "1234A"
ChracterToIncrement = MID(Value,5,1) 'gets 5th position
Num = ASC(ChracterToIncrement)
Num = Num + 1
NewCharacter = CHR(Num) 'now will be "B"

REPLACE(Value, ChracterToIncrement, NewCharacter)

Value will now be "1234B"

This should be more than enough to get u on the right
track.

Jeff
 
If this is a multi-user system, make sure you lock the table as you are
incrementing the number, so that 2 people do not get the same number. You
will also need to test for the lock and have a delay loop to cater for
conflicts. HTH - David
 
Hi David,

That is a very good point u are making. How would u go
about doint that ? To lock it & also if a another user
needs an increment at the same time how do u handle that ?
Put a pause for it to be unlocked ?

Any help & even better some code would be greatly
apprecaited I have never done anything like this before.

Thank you,
Jeff
 
Back
Top