make the first letter uppercase

shutzy

Registered User.
Local time
Today, 06:37
Joined
Sep 14, 2011
Messages
775
i would like to start making my database a little more prettier especially in the customers table. i want to make the first letter of every name etc uppercase. my staff and me are quite inconsistant so to make it easier to read and present a little better i want the formating to all be the same(apart from notes etc).

does anyone know how to do this.

sorry if this has already been asked and answered but the term could be so general i would have had to look at possibly 100's of threads to find the answer.(i have looked but not at that many)

thanks
 
Do you want the Formatting to show Upper Case or do you want to change what is entered so that you actually Store the Uppercase.

You Could look at Input Masks in the Properties to force an Uppercase letter to be entered. You could change what is entered using code. Or you could display an Uppercase letter regardless what is stored.

The other alternative is to tell the staff to enter Upper Case. This is my prefered method. It then becomes a Leadership issue. Sure you can get Access to do it for you but where does this type of thing end.

Which way do you want to go.
 
rainlover i love your optomism with regards staff. when it is down to presentation and not a particular important input issue i would rather it be my control not theirs. as far as do i want it to simply display the way i want it or stored that way. i think it is really down to my list boxes. would they display what is stored or can i also format them. i think its the first but im not experienced enough to know 100%.
 
rookie. i have read the link and it does sound very easy. i need the correct all the stored data i have already so by the link i shall use an update query(as a one time use). as far as the day to day input in the system for new customers where should i put the code? do i put it in the text box, the form. or another idea, run an update queryfor when a new customer is created, or edited?
 
I found this in my Archives. This changes what is entered and writes the result.

What is required is your prefered Error Handling.

Private Sub txtYourControl_BeforeUpdate()
Me.txtYourControl = UCase(Left(Me.txtYourControl, 1)) & Mid(Me.txtYourControl, 2)
End Sub

This gives another choice for you to choose from.

Where does it go? In design look at the properties box of the text box. There you will find an Event "Before Update".

EDIT

Changed After Update to Before Update.
 
Last edited:
I would advise you to bite the bullet and search the forum on proper case, you can use google to aid this see the sticky , at the start of the general forum I think.

Here you will find code that copes with the Mc and O'Rielly types.

Brian
 
Proper case in in the link that MSAccessRookie supplied.
 
If you want it to do it real time as they type make a function:

Code:
Public Function properCase(keyNumber As Integer, str As String)

    If Len(str) = 0 Or Right(str, 1) = " " Then
        properCase = Asc(UCase(Chr(keyNumber)))
  
    Else
        properCase = keyNumber
        
    End If

End Function

and then call it on the keypress method of the field:

Code:
Private Sub YourTextField_KeyPress(KeyAscii As Integer)
    KeyAscii = properCase(KeyAscii, ActiveControl.Text)
End Sub

This only works for text typed at the end of the field. But it works pretty good otherwise so far.
 
here's one that tidies stuff up at the same time.

gets rid of multiple spaces, and capitalizes each word in the string

Code:
Function ProperCase(s) As String
Dim n() As String
Dim x As Long
If Nz(s) = "" Then
    ProperCase = ""
    Exit Function
End If
 
s= Trim(s)
 
While InStr(s, "  ") > 0
    s = Replace(s, "  ", " ")
Wend
n = split(s, " ")
For x = 0 To UBound(n)
    n(x) = UCase(Left(n(x), 1)) & LCase(Mid(n(x), 2))
Next
ProperCase = Join(n, " ")
End Function


PHP:
?propercase(" fred            bLoGGs") 
Fred Bloggs
 
i would like to start making my database a little more prettier especially in the customers table. i want to make the first letter of every name etc uppercase. my staff and me are quite inconsistant so to make it easier to read and present a little better i want the formating to all be the same(apart from notes etc).

does anyone know how to do this.

sorry if this has already been asked and answered but the term could be so general i would have had to look at possibly 100's of threads to find the answer.(i have looked but not at that many)

thanks

I've been trying to figure this out. Doesn't Access have an autocorrect that capitalizes the first letter of a sentence? So when I type in a field it should do that. Unless I completely misunderstand what that means.
 
Private Sub Last_Name_AfterUpdate()
Me.[Last Name] = StrConv(Me.[Last Name], vbProperCase)
End Sub
 
put in a module, doenst only capitalized the first letter, but make the successing letters in small caps, making them proper.
Code:
Public Function fnCapitalizeFirstLetter(ByVal s As String) As String
    Dim lngLen As Long
    Dim l As Long
    Dim bolSkip As Boolean
    Dim sChar As String
    lngLen = Len(Trim(s & ""))
    If lngLen = 0 Then Exit Function
    l = 1
    While l <= lngLen
        sChar = Mid(s, l, 1)
        If sChar = " " Then
            bolSkip = False
        Else
            If isChar(sChar) Then
                If Not bolSkip Then
                    If l = 1 Then
                        s = UCase(sChar) & Mid(s, l + 1)
                    Else
                        s = left(s, l - 1) & UCase(sChar) & Mid(s, l + 1)
                    End If
                    bolSkip = True
                Else
                    If l = 1 Then
                        s = LCase(sChar) & Mid(s, l + 1)
                    Else
                        s = left(s, l - 1) & LCase(sChar) & Mid(s, l + 1)
                    End If
                End If
            End If
        End If
        l = l + 1
    Wend
    fnCapitalizeFirstLetter = s
End Function

Public Function isChar(s As Variant) As Boolean
    Dim intAscii As Integer
    s = left(s & "", 1)
    If Len(s) = 0 Then Exit Function
    intAscii = Asc(s)
    isChar = (intAscii >= 65 And intAscii <= 90)
    If Not (isChar) Then isChar = (intAscii >= 97 And intAscii <= 122)
End Function
 
put in a module, doenst only capitalized the first letter, but make the successing letters in small caps, making them proper.
Code:
Public Function fnCapitalizeFirstLetter(ByVal s As String) As String
    Dim lngLen As Long
    Dim l As Long
    Dim bolSkip As Boolean
    Dim sChar As String
    lngLen = Len(Trim(s & ""))
    If lngLen = 0 Then Exit Function
    l = 1
    While l <= lngLen
        sChar = Mid(s, l, 1)
        If sChar = " " Then
            bolSkip = False
        Else
            If isChar(sChar) Then
                If Not bolSkip Then
                    If l = 1 Then
                        s = UCase(sChar) & Mid(s, l + 1)
                    Else
                        s = left(s, l - 1) & UCase(sChar) & Mid(s, l + 1)
                    End If
                    bolSkip = True
                Else
                    If l = 1 Then
                        s = LCase(sChar) & Mid(s, l + 1)
                    Else
                        s = left(s, l - 1) & LCase(sChar) & Mid(s, l + 1)
                    End If
                End If
            End If
        End If
        l = l + 1
    Wend
    fnCapitalizeFirstLetter = s
End Function

Public Function isChar(s As Variant) As Boolean
    Dim intAscii As Integer
    s = left(s & "", 1)
    If Len(s) = 0 Then Exit Function
    intAscii = Asc(s)
    isChar = (intAscii >= 65 And intAscii <= 90)
    If Not (isChar) Then isChar = (intAscii >= 97 And intAscii <= 122)
End Function

This code works perfectly, thanks
 
I wrote a couple functions many years back to solve this exact problem. The basic technique is that there is a first function which breaks up a string into separate words and stores each word as an array element. Then a the code loops through each array element and converts the first letter of each word to upper case.

There are a couple nice features about the code. There's a string variable which holds each character that could be considered a word ending. For example "steve_pupel" or "steve.pupel" ... they _ or the . are considered word ending characters so that in both cases the S and the P will be converted to upper case.

Also there's a list of special words that should be all caps, like "usa" my code will convert that to USA. If the word has no vowels, then the code assumes it's an acronym and converts the entire word to upper.

Function Proper(TextString As String) As String
Dim aWord(40) As String
Dim aWordEndingCharacter(40) As String
Dim BuildString As String, PreviousCharacter As String, CurrentCharacter As String
Dim CapPriorToList As String ' Function should capitalize letters following any character in this string
Dim i As Integer, WordCounter As Integer, PreviousWordEnding As Integer, StringLength As Integer
Dim EnglishAlphabet As String
CapPriorToList = " `~.,()*!@&/|\_"
EnglishAlphabet = "abcdefghijklmnopqrstuvwxyz"
BuildString = ""
PreviousCharacter = " "
WordCounter = 1
PreviousWordEnding = 0
For i = 1 To Len(Trim(TextString))
CurrentCharacter = Mid(TextString, i, 1)
'If InStr(1, CapPriorToList, CurrentCharacter) <> 0 Then
If InStr(1, EnglishAlphabet, CurrentCharacter) = 0 Then
If PreviousWordEnding + 1 = i Then
aWord(WordCounter) = CurrentCharacter
Else
StringLength = i - PreviousWordEnding - 1
aWord(WordCounter) = Mid(TextString, PreviousWordEnding + 1, StringLength)
WordCounter = WordCounter + 1
aWord(WordCounter) = CurrentCharacter
End If
PreviousWordEnding = i
WordCounter = WordCounter + 1
Else
If i = Len(Trim(TextString)) Then
StringLength = i - PreviousWordEnding
aWord(WordCounter) = Mid(TextString, PreviousWordEnding + 1, StringLength)
End If
End If
Next i
For i = 1 To WordCounter
BuildString = BuildString & SimpleProper(aWord(i))
Next i
Proper = BuildString
End Function


Function SimpleProper(TextString As String) As String
Dim WordList As String
Dim WordListContinue As Boolean
Dim WordListPosition As Integer, WordListEndPosition As Integer, WordList2Position As Integer
Dim CurrentWordFromList As String
Dim WordIsInWordList As Boolean
Dim TwoCharacterWordStartList As String, wordlist2 As String
' This code written by self proclaimed computer genius, Steve Pupel
TwoCharacterWordStartList = "Mc**"
WordList = ";II;III;IV;VI;SIP;FAA;VAT;DD;OTCA;PV;BV;MGA;BIW;SQ;UK;USA;RJVI;LLC;IBA;PO;"
wordlist2 = ";St;Ct;th;Dr;Fl"
WordListContinue = True
WordListPosition = 1
WordIsInWordList = False
If InStr(1, WordList, ";" & Trim(TextString) & ";") = 0 Then
WordList2Position = InStr(1, wordlist2, ";" & Trim(TextString) & ";")
If WordList2Position = 0 Then
If Len(TextString) = 0 Then
SimpleProper = ""
Else
If InStr(1, TextString, "a") = 0 And InStr(1, TextString, "e") = 0 And InStr(1, TextString, "i") = 0 And InStr(1, TextString, "o") = 0 And InStr(1, TextString, "u") = 0 And InStr(1, TextString, "y") = 0 Then
SimpleProper = UCase(TextString)
Else
WordListPosition = InStr(1, TwoCharacterWordStartList, Left(TextString, 2))
If WordListPosition <> 0 And Len(Trim(TextString)) > 2 Then
SimpleProper = Mid(TwoCharacterWordStartList, WordListPosition, 2) & UCase(Mid(TextString, 3, 1)) & LCase(Mid(TextString, 4, Len(TextString) - 3))
Else
SimpleProper = UCase(Left(TextString, 1)) & LCase(Mid(TextString, 2, Len(TextString) - 1))
End If
End If
End If
Else
SimpleProper = Mid(wordlist2, WordList2Position + 1, Len(Trim(TextString)))
End If
Else
SimpleProper = UCase(TextString)
End If
End Function
 
Thank you Steve,
I did copy the code in my code database, I will certainly test it.

Thank you for having take the time to help.

Claude
 
You could just use something like this?

Code:
tt="Welcome to the pleasuredome"
? Ucase(Left(tt,instr(tt," ")-1)) & Mid(tt,instr(tt," "))
WELCOME to the pleasuredome
 
You could just use something like this?

Code:
tt="Welcome to the pleasuredome"
? Ucase(Left(tt,instr(tt," ")-1)) & Mid(tt,instr(tt," "))
WELCOME to the pleasuredome

That a great hack... But I made a terrible mistake when asking the question, I meant:

How to make just the first letter of the first word in upper case?

Example:

"MY NAME IS DIOGO. THANKS FOR ASKING!" should be turned to:
"My name is Diogo. Thanks for asking!"
 
Well again, that is not what you are asking.
You appear to be asking for the first word of each sentence?, but then have diogo as Diogo.?

How is one meant to identify 'special' words?
If every sentence ends in a full stop (as it should?) then you could split using that character, set first character to uppercase and concatenate the split strings back together.?
For that I would write a function.

However I do not have any idea at the moment on how to identify diogo as a word to proper.?
 

Users who are viewing this thread

Back
Top Bottom