Auto incrementing letter part of an alphanumeric key

We can replace your code in just one line. Just let me know the outcome of the above.

That's very promising! I can't wait to break the back of it, although it gives me an #Error when I test it. What could probably cause such an error?
 
Copy and paste the following into the Control Source of a textbox for the sake of testing:
Code:
[COLOR=red]=[/COLOR]UCase(Chr(Asc(Nz(DMax("[COLOR=red][[/COLOR]Letter[COLOR=red]][/COLOR]", "T_M_AutoClaimNo", "[COLOR=red][[/COLOR]GroupType[COLOR=red]] [/COLOR]= 'GC'"), [COLOR=red]"@"[/COLOR])) + 1))
I made a slight mistake there. 96 should have been "@". I also added some extra bits - highlighted in red.
 
It gives me the same error again
 
And what do you get when you:
Code:
=DMax("[Letter]", "T_M_AutoClaimNo", "[GroupType] = 'GC'")
?
 
Ok, we're going to keep adding to the code. This:
Code:
=Asc(Nz(DMax("[Letter]", "T_M_AutoClaimNo", "[GroupType] = 'GC'"), "@"))
?

And are you sure when you copied the copied you didn't miss off a parens?
 
Ok, we're going to keep adding to the code. This:
Code:
=Asc(Nz(DMax("[Letter]", "T_M_AutoClaimNo", "[GroupType] = 'GC'"), "@"))
?

And are you sure when you copied the copied you didn't miss off a parens?

the number 64 appears
 
And finally,
Code:
=Chr(Asc(Nz(DMax("[Letter]", "T_M_AutoClaimNo", "[GroupType] = 'GC'"), "@")) + 1)
?

NB: I realised we don't need Ucase()
 
So you must have missed off a parenthesis when you copied the code. It happens sometimes in these boxes.

I'm guessing you know how to do the other bits?
 
I already set the format of the [letter] field to '>' to get it in upper case
 
So you must have missed off a parenthesis when you copied the code. It happens sometimes in these boxes.

I'm guessing you know how to do the other bits?

Well, honestly I'm trying to place it somewhere in my function, I don't know if it's going to work in the VBA editor though.
 
I thought I told you that we can replace your function with one line of code? You don't want to let the hardwork you put into writing that function just go to waste ;)
 
Lol, That's "Programming world", I have to get used to it. :o

Now I'm trying to make use of that effective one line of code to generate the key in it's final format.
 
Where's the Year coming from? I've just put 2010 in there so you can amend the code to suit:
Code:
="CLM/GC/" & Format(Nz(DMax("[Letter]", "T_M_AutoClaimNo", "[GroupType] = 'GC'"), 0) + 1, "0000") & "2010" & Chr(Asc(Nz(DMax("[Letter]", "T_M_AutoClaimNo", "[GroupType] = 'GC'"), "@")) + 1)
 
The year comes from the function parameter, I've amended it and it works perfectly! Finally, it's done! :D Thank you, vbaInet!
 

Users who are viewing this thread

Back
Top Bottom