Solved

Increment an Alpha Character to Next Letter in textbox

Posted on 2009-05-13
5
552 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

786 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