Solved

Increment an Alpha Character to Next Letter in textbox

Posted on 2009-05-13
5
556 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
[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
  • 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

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…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

623 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