Results 1 to 4 of 4

Thread: Upper case 1st letter

  1. #1
    Join Date
    Nov 2002
    Location
    Ft Worth, TX
    Posts
    1

    Question Upper case 1st letter

    I am new to the access world, but I have not been able to locate any information as to forcing the first letter of a word, such as a name, to upper case . I find information pertaining to forcing the whole word to either upper or lower case.

  2. #2
    Join Date
    Nov 2002
    Posts
    1
    What do you think about solutions like these. First for all first letter in a word (with - or blank). Second only for the first letter. On the "after update" event of course.

    Function strTitleMaj(strData As String) As String
    Dim result As String, i As Integer, cara As String
    If Not IsNull(strData) Then
    result = UCase(Mid(strData, 1, 1))
    i = 1
    Do
    i = i + 1
    cara = Mid(strData, i, 1)
    If cara = "-" Or cara = " " Then
    result = result & cara & UCase(Mid(strData, i + 1, 1))
    i = i + 1
    Else
    result = result & LCase(cara)
    End If
    Loop Until i = Len(strData)
    strTitleMaj = result
    End If
    End Function
    Function strInitialMaj(strData As String) As String
    Dim result As String
    If Not IsNull(strData) Then
    result = UCase(Left(strData, 1)) & Right(strData, Len(strData) - 1)
    Else: result = ""
    End If
    strInitialMaj = result
    End Function

  3. #3
    Join Date
    Nov 2002
    Posts
    3
    how about

    tbShortDescription = StrConv(tbShortDescription, vbProperCase)

  4. #4
    Join Date
    Nov 2002
    Posts
    3

    Smile

    'I like this routine better. Does more.

    Public Function FormattedStringTitleCase(arg_strData As String) As String
    On Error GoTo err_Exit
    'Convert first character of each word in a string to upper case.
    'Converts any letter after a space or non-alphabetic character to UCase.
    'Will call function to eliminate extra spaces.

    Dim strResult As String
    Dim i As Integer
    Dim strCharacter As String
    Dim blLetter As Boolean
    Dim intASCINumber As Integer
    Dim intStringLength As Integer
    Dim blSpaceFound As Boolean

    If Not IsNull(arg_strData) Then
    arg_strData = FormattedStringRemoveExtraSpaces(arg_strData)
    intStringLength = Len(arg_strData)
    i = 0
    blSpaceFound = True ' will force logic on first character to UCase
    Do
    i = i + 1
    strCharacter = Mid(arg_strData, i, 1)
    intASCINumber = Asc(strCharacter)
    blLetter = ((intASCINumber > 64 And intASCINumber < 91) _
    Or (intASCINumber > 96 And intASCINumber < 123) _
    Or (intASCINumber = 39))
    If blLetter = False Then
    strResult = strResult & strCharacter
    blSpaceFound = True
    Else
    If blSpaceFound = True Then
    'previous character was not a letter so capt this letter.
    strResult = strResult & UCase(strCharacter)
    Else
    strResult = strResult & strCharacter
    End If
    blSpaceFound = False
    End If
    Loop Until i = intStringLength
    FormattedStringTitleCase = strResult
    End If

    exit_Function:
    Exit Function

    err_Exit:
    'on error return original string
    FormattedStringTitleCase = arg_strData
    Resume exit_Function
    End Function

    Public Function FormattedStringRemoveExtraSpaces(arg_strData As String) As String
    On Error GoTo err_Exit
    'Will eliminate double spaces.

    Dim strResult As String
    Dim i As Integer
    Dim strCharacter As String
    Dim intStringLength As Integer
    Dim blSpaceFound As Boolean

    If Not IsNull(arg_strData) Then
    arg_strData = Trim(arg_strData)
    intStringLength = Len(arg_strData)
    i = 0
    blSpaceFound = False
    Do
    i = i + 1
    strCharacter = Mid(arg_strData, i, 1)
    If strCharacter = " " Then
    If blSpaceFound = True Then
    'skip extra space
    Else
    strResult = strResult & strCharacter
    blSpaceFound = True
    End If
    Else
    strResult = strResult & strCharacter
    blSpaceFound = False
    End If
    Loop Until i = intStringLength
    FormattedStringRemoveExtraSpaces = strResult
    End If

    exit_Function:
    Exit Function

    err_Exit:
    'return original string
    FormattedStringRemoveExtraSpaces = arg_strData
    Resume exit_Function

    End Function

Posting Permissions

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