Page 1 of 2 12 LastLast
Results 1 to 15 of 29
  1. #1
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10

    Unanswered: Format: Alpha Only

    Is there away to format a textbox to accept alpha characters only (no numbers or characters)?
    George
    Home | Blog

  2. #2
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    I think you would have to use the text box's BeforeUpdate event, and step
    through the string one character at a time, testing it against the ASCII character set.
    Inspiration Through Fermentation

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Well I've currently set the textbox (worked it out a couple of seconds ago) input mask to 'Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
    The capital denotes a required and the others are optional. This allows alpha-numeric only... So I guess my next best attempt would be to se 10 replace statements afterupdate to remove numbers?

    Surely there's an easier way?
    George
    Home | Blog

  4. #4
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    Hi

    May be this will do what you want

    Code:
    Private Sub TestText_KeyDown(KeyCode As Integer, Shift As Integer)
        If IsNumeric(Chr(KeyCode)) Then KeyCode = 0
    End Sub

    ??


    MTB

    Sorry dosn't get rid of characters !

  5. #5
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Off the top of my head, untested... Could be cleaned up, but it gives you the general idea.
    Of course, if you're using a language other than english, you'll have to change the ASCII range you're testing.

    Code:
    Sub MyTextBox_BeforeUpdate(Cancel as Integer)
    ...
    For x=1 to Len(MyTextBox)
       Select Case MID$ (MyTextBox,x,1)
        Case (<65 or >123)
           'not a letter
           MsgBox MyTextBox & " is not in a valid format"
           Cancel = True  'remove user changes
           Exit For
        Case (>91 and <123)
           If MID$(MyTextBox,x,1) < 97
              'not a letter
              MsgBox MyTextBox & " is not in a valid format"
              Cancel = True  'remove user changes
              Exit For
          End If
       Case Else
         'don't have to do anything here,  it's a letter
       End Select
    Next X
    Exit Sub
    Last edited by RedNeckGeek; 02-06-07 at 09:10.
    Inspiration Through Fermentation

  6. #6
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    Hi again

    Rev B

    Code:
    Private Sub TestText_KeyDown(KeyCode As Integer, Shift As Integer)
        If KeyCode < 65 Or KeyCode > 90 Then KeyCode = 0
    End Sub
    ??

    MTB

  7. #7
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Quote Originally Posted by MikeTheBike
    Private Sub TestText_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode < 65 Or KeyCode > 90 Then KeyCode = 0
    End Sub
    That's a very clever piece of code there!
    But...
    It doesn't stop the number pad from working *sigh*
    Last edited by gvee; 02-06-07 at 09:03.
    George
    Home | Blog

  8. #8
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    Doesn't allow for lower case characters, either....
    Inspiration Through Fermentation

  9. #9
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    Hi

    Again, again

    It stops the number pad on my PC !!!??

    Alas, it also disables the cursor, delete & back space keys.

    So Rev C

    Code:
    Private Sub TestText_KeyDown(KeyCode As Integer, Shift As Integer)
        Select Case KeyCode
            Case Is = 8, 35, 36, 37, 39, 46
            Case Is <= 65
                KeyCode = 0
            Case Is > 90
                KeyCode = 0
        End Select
    End Sub
    I will play a little longer to see if I can break it with the nimber pad !?


    Something strange going on, it allows both upper and lower case, and still disables the number pad on my PC. I;m using an A2k format file in A2k3, if that has any bearing on think !!?

    MTB
    Last edited by MikeTheBike; 02-06-07 at 09:26.

  10. #10
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    MTB,

    It blocks numpad on mine, also.
    The A key doesn't work, you should be testing for <65, not <=65.

    *scratching head*
    I don't understand why it accepts lower case letters, though.
    Inspiration Through Fermentation

  11. #11
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Quote Originally Posted by MikeTheBike
    Code:
    Private Sub TestText_KeyDown(KeyCode As Integer, Shift As Integer)
        Select Case KeyCode
            Case Is = 8, 35, 36, 37, 39, 46
            Case Is <= 65
                KeyCode = 0
            Case Is > 90
                KeyCode = 0
        End Select
    End Sub
    MTB
    This allows me to enter upper and lower case, and the number pad.
    George
    Home | Blog

  12. #12
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Private Sub TestText_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode < 65 Or KeyCode > 90 Then KeyCode = 0
    End Sub

    +

    Input Mask: Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa a

    Is not the prettiest way (small bugs where it jumps to the end of the input...) but it appears to work...
    --------------------------------------------------------------------------------------------------
    EDIT:

    No it doesn't. Foolishly I had num-lock off this time.
    *noob alarm*
    Last edited by gvee; 02-06-07 at 09:43.
    George
    Home | Blog

  13. #13
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Quick & dirty solutution for the validation rule:
    Code:
    Not Like "*[0-9]*" And Not Like "*[[&#163;&#163;$%^&*()-_=+{}'@#~/?.>,<|\`&#172;]*" And Not Like "*]*" And Not Like "*!*"
    Can't remember the escape character so a wee bit messy there
    Testimonial:
    pootle flump
    ur codings are working excelent.

  14. #14
    Join Date
    Jan 2007
    Location
    California, USA
    Posts
    520
    Ok, it's not clever, but works:
    Code:
    Private Sub AlphaOnly_BeforeUpdate(Cancel As Integer)
      If Not AllowOnlyAlpha(AlphaOnly) Then
        Cancel = True
        MsgBox "Only alpha characters are allowed in this field.  Please try again."
      End If
    End Sub
    
    Function AllowOnlyAlpha(mInput) As Boolean
      Dim x As Integer
      Dim a As Integer
      For x = 1 To Len(mInput)
        a = Asc(Mid(mInput, x, 1))
        If (a >= 65 And a <= 90) Or (a >= 97 And a <= 122) Then
          'This is an alpha character
        Else
          AllowOnlyAlpha = False
          Exit Function
        End If
      Next x
      AllowOnlyAlpha = True
    End Function

  15. #15
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    hmm, you're right, it does work... but it's not the most user friendly thing I ever did see
    I want to disable these characters put in - much like MikeTheBikes suggestion in post#6
    I will try tweaking all the suggestions so far into one uber-suggestion

    Keep those suggestions coming!

    Cheers <3
    George
    Home | Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •