How can I capitalise the first letter of each word in Text Box - .

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Trying to get words in text box to appear with each 1st letter capitalised -
I used to be able to do this in Dataease.........
 
Trying to get words in text box to appear with each 1st letter capitalised -
I used to be able to do this in Dataease.........

On the Form's control's AfterUpdate event code:
Me![ControlName] = StrConv([ControlName],3)

Note: this will incorrectly capitalize some words which contain more
than one capital, i.e. O'Brien, MacDonald, IBM, Jones-Smith, ABC,
etc., and incorrectly capitalize some words that should not have any
capitals, or whose capitaliztion depends upon usage, such as e. e.
cummings, abc, van den Steen.
Then some names can be capitalized in more than one manner, depending
upon personal preference, i.e. O'Connor and O'connor, McDaniels and
Mcdaniels, etc. are both correct.

You can create a table of exceptions and have the code use DLookUp
with a message if one of the exception words is found.
 
The AutoCorrect can help. See Tools / AutoCorrect options. Use with
extreme caution.
 
I was aware of the wrong capitilsation of some words problem, but thank you
so much for your very helpful reply !!!!

Regards, Ian
 
First, create a public function in a module that can be accessed by
other text boxes if need be.

Public Function prcProperCase(ByVal varSTRING As String) As String
On Error GoTo HandleErr
Dim arrWORDLIST
Dim x As Integer

'split words into an array
arrWORDLIST = Split(varSTRING, " ")

'capitalize each word and put back into same string
For x = 0 To UBound(arrWORDLIST)
prcProperCase = prcProperCase & UCase(Left(arrWORDLIST(x), 1)) _
& Mid(arrWORDLIST(x), 2) & " "
Next

prcProperCase = Trim(prcProperCase)
ExitHere:
Exit Function
HandleErr:
prcCAPITALIZE = ""
Call MsgBox("ERROR " & Err.Number & ": " & Err.Description,
vbCritical, "global.prcCAPITALIZE")
End Function


Call this function in the Change or Exit event of the text box.
On Change will run the function after every keystroke, On Exit will run
the function when you try to leave the textbox.

Private sub TextBox1_Change()
TextBox1 = prcProperCase(TextBox1)
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top