Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

start input always with capital, rest in lower case 2

Status
Not open for further replies.

rene1000

IS-IT--Management
Apr 9, 2002
89
NL
I have an textbox which is used to enter peoples first names. I want to change the first character to upper case and all other characters to lower case using vba on the after update event. How can i do this ?
 
Hi!

In the input mask for the control, use for instance:

>?<??????????????????????;;_

The number of '?' represents the number of charachters you want the user to be able to enter in the control (field)

HTH Roy-Vidar
 
Oups - did'nt see the vba-part, sorry

A simple approach could then be:

me!NameOfControl = ucase(mid$(me!NameOfControl,1,1)) & lcase(mid$(me!NameOfControl,2)

HTH Roy-Vidar
 
How about...

Private Sub txtFirstName_AfterUpdate()
LastName = StrConv(txtFirstName, vbProperCase)
End Sub

HTH,
Bob
Your mileage may vary, but following the guidelines in faq181-2886 will help you reach your goal.
 
CORRECTION:

Private Sub txtFirstName_AfterUpdate()
txtFirstName = StrConv(txtFirstName, vbProperCase)
End Sub

Sorry - need another cup of coffee!
 
Thanx for the star, but actually I think Bob's code is better. Why:

With strConv using vbpropercase, each word gets a Ucase first letter. So if my first name had been Roy Vidar, typing roy vidar would have produced 'Roy Vidar', but unfortunately my parents put in that '-' thingie which &quot;¤&£ up the whole thing. This might be solved by:

Dim lStart As Long
lStart = InStr(Me!NameOfControl, &quot;-&quot;)
If lStart <> 0 Then
Me!NameOfControl = UCase(Mid$(Me!NameOfControl, 1, 1)) & _
LCase(Mid$(Me!NameOfControl, 2, lStart - 1)) & _
UCase(Mid$(Me!NameOfControl, lStart + 1, 1)) & _
LCase(Mid$(Me!NameOfControl, lStart + 2))
Else
Me!NameOfControl = StrConv(Me!NameOfControl, vbProperCase)
End If

This should work with one occurence of '-' in the first name. I've never seen more;-)

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top