Article ID: 110391
Article Last Modified on 5/6/2003
'**********************************************************
' Declarations section of the module
'**********************************************************
Option Explicit
'==========================================================
' The following function is designed for use in the AfterUpdate
' property of form controls.
' Features:
' - Leading spaces do not affect the function's performance.
' - "O'Brian" and "Wilson-Smythe" will be properly capitalized.
' Limitations:
' - It will change "MacDonald" to "Macdonald."
' - It will change "van Buren" to "Van Buren."
' - It will change "John Jones III" to "John Jones Iii."
'==========================================================
Function Proper (AnyValue As Variant) As Variant
Dim ptr As Integer
Dim TheString As String
Dim currChar As String, prevChar As String
If IsNull(AnyValue) Then
Exit Function
End If
TheString = CStr(AnyValue)
For ptr = 1 To Len(TheString) ' Go through each char. in
' string.
currChar = Mid$(TheString, ptr, 1) ' Get the current character.
Select Case prevChar ' If previous char. is a
' letter,'this char. should be
' lowercase.
Case "A" To "Z", "a" To "z"
Mid(TheString, ptr, 1) = LCase(currChar)
Case Else
Mid(TheString, ptr, 1) = UCase(currChar)
End Select
prevChar = currChar
Next ptr
AnyValue = theString
End Function
AnyValue= theString
End Function
Proper=CVar(theString)
End FunctionField: Full Name:Proper([Last Name] & " " & [First Name]) This will concatenate the first and last names and capitalize the first letter of each.
TextBox --------------------------------- ControlName: AddressP ControlSource: =Proper([Address]) NOTE: In calculated fields, the ControlName must be unique.
Action: SetValue Item: Screen.ActiveControl Expression: Proper(Screen.ActiveControl) NOTE: You can call this macro from the AfterUpdate property of a control on a form. This has the same affect as the first version of the Proper() function.
Additional query words: proper
Keywords: kbhowto kbprogramming KB110391