make the first letter uppercase (1 Viewer)

shutzy

Registered User.
Local time
Today, 00:54
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
 

RainLover

VIP From a land downunder
Local time
Today, 09:54
Joined
Jan 5, 2009
Messages
5,041
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.
 

shutzy

Registered User.
Local time
Today, 00:54
Joined
Sep 14, 2011
Messages
775
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%.
 

shutzy

Registered User.
Local time
Today, 00:54
Joined
Sep 14, 2011
Messages
775
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?
 

RainLover

VIP From a land downunder
Local time
Today, 09:54
Joined
Jan 5, 2009
Messages
5,041
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:

Brianwarnock

Retired
Local time
Today, 00:54
Joined
Jun 2, 2003
Messages
12,701
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
 

RainLover

VIP From a land downunder
Local time
Today, 09:54
Joined
Jan 5, 2009
Messages
5,041
Proper case in in the link that MSAccessRookie supplied.
 

gotlength

Registered User.
Local time
Yesterday, 16:54
Joined
Apr 19, 2013
Messages
12
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.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 00:54
Joined
Sep 12, 2006
Messages
15,634
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
 

samsung

New member
Local time
Yesterday, 18:54
Joined
May 20, 2013
Messages
1
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.
 

azizmech

New member
Local time
Today, 02:54
Joined
Jan 31, 2016
Messages
3
Private Sub Last_Name_AfterUpdate()
Me.[Last Name] = StrConv(Me.[Last Name], vbProperCase)
End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 07:54
Joined
May 7, 2009
Messages
19,231
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
 

toumack

Registered User.
Local time
Yesterday, 16:54
Joined
May 14, 2011
Messages
13
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
 

StevePupel

New member
Local time
Yesterday, 19:54
Joined
Nov 13, 2007
Messages
8
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
 

toumack

Registered User.
Local time
Yesterday, 16:54
Joined
May 14, 2011
Messages
13
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
 

DBApprentice

On Error GoTo AWF *****:
Local time
Yesterday, 20:54
Joined
Dec 24, 2018
Messages
150
here's one that tidies stuff up at the same time.

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

Gemma the Husky, how can I change your code to have just the first word in Upper Case?
 

Gasman

Enthusiastic Amateur
Local time
Today, 00:54
Joined
Sep 21, 2011
Messages
14,231
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
 

DBApprentice

On Error GoTo AWF *****:
Local time
Yesterday, 20:54
Joined
Dec 24, 2018
Messages
150
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!"
 

Gasman

Enthusiastic Amateur
Local time
Today, 00:54
Joined
Sep 21, 2011
Messages
14,231
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

Top Bottom