Solved

access 2007 vba using chr()

Posted on 2010-08-24
2
454 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now