Capitalizing fields

  • Thread starter Thread starter kwbmail
  • Start date Start date
K

kwbmail

Guest
I need to force capitalization of the first letter in a text field, but without forcing the rest of the field to be any particular format.

For example, I can use an input mask of:
>L<?????????
which would work for entering a city name like "Detroit", but it won't work for entering the name "Hazel Park" since there needs to be another capital letter in the middle of the rest.

How do I force capitalization of the first character and then ignore the rest?
 
here is an answer that may help.

Create this Public Sub in a Module

Public Sub UpperCaseText(ctr As Control)
Dim intLen As Integer
Dim x As Integer
Dim stString As String
DoCmd.RunCommand acCmdSaveRecord
stString = ctr.Text
intLen = Len(stString)
For x = 1 To intLen
Select Case x
Case 1
stString = UCase(Left(stString, 1)) & Mid(stString, 2)
Case Else
stString = UCase(Left(stString, 1)) & Mid(stString, 2)
If Mid(stString, x - 1, 1) = " " Then
stString = Left(stString, x - 1) & UCase(Mid(stString, x, 1)) & Mid(stString, x + 1)
End If
End Select
Next x
ctr = stString

End Sub


Now on the AfterUpdate of the text field add this code:

Call UpperCaseText(Screen.ActiveControl)

This makes the code generic enough to use everywhere you want to do this, including People name fields.

I recommend the AfterUpdate as this will be less intrusive to the person inputting the data. Also get rid of the Input Mask, this is limited as you have found out.

[This message has been edited by Travis (edited 12-17-1999).]
 
Try the StrConv Function in Access, you can select uppercase, lowercase, or Proper Case (which is what it sounds like you want to do).
 

Users who are viewing this thread

Back
Top Bottom