Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2007
    Location
    Stalybridge, Manchester
    Posts
    273

    Unanswered: Upper & Lower Case

    Is there away of being able to change how someone inputs data into a txtBox

    What I mean is say in my txtBox I enter Jez, another user may type jez or JEZ, is it possible to run something that after the update it converts the input to Jez?

    This will only be used for Foremane & Surnames

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    you could try to use a format mask, although whether it would do precisley what you want I dunno

    probably the best solution is to use one of the string functions, IIRC there is strProper along with strUpper, strLower.

    if you put the code in (say) the on change event that should get close to what you want.
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by healdem
    you could try to use a format mask, although whether it would do precisley what you want I dunno

    probably the best solution is to use one of the string functions, IIRC there is strProper along with strUpper, strLower.

    if you put the code in (say) the on change event that should get close to what you want.
    ditch that strupper is form another language (VB perhaps), in access its UCASE or LCASE.
    so mebbe theres scope for a function called PCASE.....
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    instead consider using a function such as...
    Code:
    Public Function PCASE(myString As String) As String
    If IsNull(myString) Or Len(myString) < 1 Then
      PCASE = "" 'lets make this null safe code for the heck of it
    Else
      'first off convert all text to lower case
      myString = LCase(myString)
      'the first character is always upper case
      myString = UCase(Left$(myString, 1)) & Mid$(myString, 2)
      'then look for anything preceded by a space, make that upper case
      Dim StartAt As Integer 'thios will holdd the position of the searched for symbol
      StartAt = 1 'make sure we enter the code at least once
      Do
        StartAt = InStr(StartAt, myString, " ") 'search for a space
        If StartAt > 0 Then 'if startat was more than zero we found a space
          myString = Left$(myString, StartAt) & UCase(Mid$(myString, StartAt + 1, 1)) & Mid$(myString, StartAt + 2)
          'so repalce the character after the space with an upper case version of that character
          StartAt = StartAt + 1 ' make sure we don't find the same space next time round
        End If
      Loop Until StartAt = 0 'makes sure we go through the loop at least once
    End If
    PCASE = myString 'assign our working copy of the string to the return value
    End Function
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Apr 2007
    Location
    Stalybridge, Manchester
    Posts
    273
    Excellent, thanks for this...

    So I just tun this from a module and call PCASE from the AfterUpdate event on my txtBox?

  6. #6
    Join Date
    Apr 2007
    Location
    Stalybridge, Manchester
    Posts
    273
    I have tried this below

    Code:
    Private Sub txtForename_AfterUpdate()
        PCASE
    End Sub
    and keep getting an error message

    Compile error: Argument not optional

    am I having a bad day or have I done something wrong?

  7. #7
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    You have to pass it the value to propercase and assign the return value to something. This will get you there.
    Code:
    me.mytextbox.value = PCase(me.mytextbox.value)
    George
    Home | Blog

  8. #8
    Join Date
    Apr 2007
    Location
    Stalybridge, Manchester
    Posts
    273
    Excellent, that works great

  9. #9
    Join Date
    Mar 2009
    Posts
    120
    Thanks guys. THis helped me with converting Lower Case to Upper Case. I just substituted the PCase for UCase and it works Great.

Posting Permissions

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