Solved

Increment an Alpha Character to Next Letter in textbox

Posted on 2009-05-13
5
554 Views
Last Modified: 2012-05-06
Access 2003
vba code

What I have:
In the code below.
When a person uses...ctrl+shift+f5
It increments a Nueric value by +1

What i   need:

U have another textbox.
That if there ia an "Alpha" Character ...go to the nextv letter in the alphabet.

So if the field is field  fldLevel

and the value in the field is   "B"  when I hit ctrl+Shift+f5...  I wantr the letter to go to "C"

Thanks
fordraiders






What I need:

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
 
If Shift = 3 And KeyCode = vbKeyF5 Then
If IsNumeric([fldLocation4]) Then
    [fldLocation4] = [fldLocation4] + 1
ElseIf IsNull([fldLocation4]) Then
    [fldLocation4] = 1
Else
    MsgBox "Must Manually Enter AlphaNumeric Code Values.!", vbCritical, "Error!"
KeyCode = 0
Me.fldLocation4.SetFocus
Exit Sub
End If
End Sub

Open in new window

0
Comment
Question by:fordraiders
  • 4
5 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 24379063
Convert to decimal then add one. Of course you would need to put validation to ensure they dont exceed past Z
eg

asc converts to decimal and chr converts decimal back to letter

fldLevel= chr$(asc(fldLevel)+1)
0
 
LVL 3

Author Comment

by:fordraiders
ID: 24379239
Rock, Thanks...Fogot a checkpoint..
Need to make sure...Value is strictly a Alpha character ?

Thanks
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24379324
no worries, lower or upper range?
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 24379551
lets assume upper

if it reaches Z, what do u want it to do, go back to A?

dim iLetter as integer

'If no value make it A
if isnull(fldLevel) then
    fldLevel = "A"

'If Z then wrap to A
elseif fldLevel = "Z" then
    fldLevel = "A"
else

'Check if between range of A to Y, if so then add one and get next letter else throw error
    iLetter = asc(fldLevel)
    if iLetter >= 65 and iLetter <= 89 then
        fldLevel = chr$(iLetter+1)
    else
        msgbox "Invalid"
    end if
end if
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24379567
If u want something other than go back to A when its Z then simply add what u want there, I have seperated it out. I am going offline now, so will catch up on this tomorrow
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
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…

726 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