Solved

Increment an Alpha Character to Next Letter in textbox

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of utilizing SQL Server functions 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 Ac…
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.

746 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

11 Experts available now in Live!

Get 1:1 Help Now