Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Increment an Alpha Character to Next Letter in textbox

Posted on 2009-05-13
5
Medium Priority
?
562 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 2000 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

876 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