Solved

access 2007 vba using chr()

Posted on 2010-08-24
2
487 Views
Last Modified: 2013-11-27
I am working on a function to automatically create a lot number.

This is the format:  GAA0001

It first gets the last lot number used from the table.
Then look at the numeric section to see if it is at 9999.
If so, it needs to look increment the 3rd letter.  If the 3rd letter is Z, it should set it to A and increment the 2nd letter.

I know that chr(65)  is "A" and chr(90) is Z

Is there a way to work on the 3rd letter like this?
strCharacters = "GAA1234"
strLetter = mid(strCharacters, 3)
if strLetter is greater than chr(90) then
      strLetter = chr(65)
endif

Then I'll go on to look at and increment the 2nd letter if needed.

I know I have data type mismatches in there... that is what I'm trying work around.

Thanks,
Brooks
0
Comment
Question by:gbnorton
  • 2
2 Comments
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 33514347
Use ASC - If Asc(StrLetter) > 90 Then StrLetter = 65
0
 
LVL 95

Accepted Solution

by:
Lee W, MVP earned 500 total points
ID: 33514367
ASC should take the ASCII value of the character and check itYou can also change the case in advance so you don't need to do that.strCharacters = "GAA1234"strLetter = mid(UCase(strCharacters), 3)if strLetter is greater than chr(90) then      strLetter = chr(65)endifThe added UCASE should change the case to upper case so you ALWAYS get a character between 65 and 90.
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question