Capitalisation Recognise Spaces

AWilderbeast

Registered User.
Local time
Today, 07:25
Joined
Sep 13, 2005
Messages
92
Right ive searched the forum and people are just asking silly questions that can be answered with an input mask but.

What im looking for is to be able to type a name for example in one textbox and the textbox will Capitalize the first Name and recognise the space key has been pressed and Capitalize the first letter of Second Name

Thanks for any help
 
Try this:

Your fieldname is in this example txtField

In your VBA-code:

Me.txtField.Value = UCase(Mid(Me.txtField.Value, 1, 1)) & Mid(Me.txtField.Value, 2, InStr(1, Me.txtField.Value, " ") - 1) & UCase(Mid(Me.txtField.Value, InStr(1, Me.txtField.Value, " ") + 1, 1)) & Mid(Me.txtField.Value, InStr(1, Me.txtField.Value, " ") + 2, Len(Me.txtField.Value) - InStr(1, Me.txtField.Value, " ") + 1)

That should do the trick, on the condition that the name exists out of two words. You can tune this code by checking the amount of words and such. Also include a condition for when there is only a name, and not a first name, because the code above cannot handle 1 word.

Greetz,

Seth
 
Why not use the StrConv function in the AfterUpdate of the text box? This will convert the keyed text into proper case. i.e. john doe = John Doe
Code:
Sub Textbox1_AfterUpdate()
TextBox1 = StrConv(TextBox1, vbProperCase)
End Sub
 

Users who are viewing this thread

Back
Top Bottom