?
Solved

access 2007 vba using chr()

Posted on 2010-08-24
2
Medium Priority
?
508 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 96

Expert Comment

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

Accepted Solution

by:
Lee W, MVP earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

752 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