Capitalize first letter in text box

S

setabery

Is there a way to capitalize the first letter entered into a text box,
such as a field that would ask for a Name?
 
A

Arvin Meyer [MVP]

Is there a way to capitalize the first letter entered into a text box,
such as a field that would ask for a Name?

This should work for you. Substitute your textbox name for Text0:

Private Sub Text0_KeyUp(KeyCode As Integer, Shift As Integer)
' Changes first character in a text box to Sentence Case
' Arvin Meyer 4/30/1999
On Error GoTo Err_Text0
If Len(Me.Text0.Text) = 1 Then
KeyCode = Asc(Me.Text0.Text)
If KeyCode >= 90 And KeyCode <= 122 Then
KeyCode = KeyCode - 32
Me.Text0.Text = Chr$(KeyCode)
Me.Text0.SelStart = Me.Text0.SelLength + 1
End If
End If

Exit_Text0:
Exit Sub

Err_Text0:
MsgBox Err.Description
Resume Exit_Text0
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

Top