NZ

  • Thread starter Thread starter DS
  • Start date Start date
D

DS

I have this two part statement that gets the highest record then adds to
it. The problem is if a number is just a number and no letter exsists
it doesn't add a letter...such as 2 ends up as 2, not 2A....
but it does work if I have 2A, it does make it 2B. Also do these have
to be in seperate statements? Can't they be one, if so then how.
Thanks
DS



'DMAX
Me.TxtLast = DMax("[NumberID]", "tblTest", "Left(NumberID,Len(" &
Me.TxtCurrent & ")) = '" & Me.TxtCurrent & "'")

'ADD
Me.TxtNew = Left(Me.TxtLast, Len(Me.TxtLast) - 1) &
Chr(Asc(right(Me.TxtLast, 1)) + 1)
 
Sorry DS but you could have written 4 loop codes to do what you are asking
PROPERLY in the time you have been trying Len DMax Val Left Right.........and
it wouldn't be processor intensive either, it would allow for any and all
eventualities if properley coded! plus whilst I'm having a bit of a dig 2A is
NOT A NUMBER 2 is a number A is a letter!! :p

Anyway, in answer to this question;
Me.TxtNew = Left(Me.TxtLast, Len(Me.TxtLast) - 1) &
Chr(Asc(right(Me.TxtLast, 1)) + 1)
won't work on 2 as you are asking it to work out the Ascii value of a string
with a length of 1 minus 1 = 0 so it fails, in fact it won't work on any
value as you want it to if its just numbers, for example if you type 44 it
will give you 5 as answer.

If you don't mind you code being very haphazard, then you could try;
Me.txtnew = IIf(Right(Me.TxtLast, 1) <= Chr(57), Left(Me.TxtLast,
Len(Me.TxtLast)) & "a", Left(Me.TxtLast, Len(Me.TxtLast) - 1) &
Chr(Asc(Right(Me.TxtLast, 1)) + 1))

just don't put in 5z or 47% !!!!!

TonyT..

DS said:
I have this two part statement that gets the highest record then adds to
it. The problem is if a number is just a number and no letter exsists
it doesn't add a letter...such as 2 ends up as 2, not 2A....
but it does work if I have 2A, it does make it 2B. Also do these have
to be in seperate statements? Can't they be one, if so then how.
Thanks
DS



'DMAX
Me.TxtLast = DMax("[NumberID]", "tblTest", "Left(NumberID,Len(" &
Me.TxtCurrent & ")) = '" & Me.TxtCurrent & "'")

'ADD
Me.TxtNew = Left(Me.TxtLast, Len(Me.TxtLast) - 1) &
Chr(Asc(right(Me.TxtLast, 1)) + 1)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Error 3464 9
DMax Problem 8
ID with Alpha 2
DMax Problem (Type Mismatch) 11
Alpha Incrementing 7
Going to end of field prob. SelStart?? 1
Help with code. 3
Auto increment Not Functioning Correctly 2

Back
Top