tf37
Board Regular
- Joined
- Apr 16, 2004
- Messages
- 169
Need just a little bit of help here
I found the following code to help resolve hyphenated names, but need to tweak when you have more than one hyphen in a name
ie: the name is mary-joe jane > it works okay Mary-Joe Jane, but if the name is: mary-joe-jane smith it does Mary-Joe-jane Smith
I have a private sub and it calls the public function:
Private Sub PayTo_AfterUpdate()
' 09-16-20 tf attempt to have pay to name in proper case without manually doing it
' appears to work properly - yea!!
' does not handle hyphenated names
' found code to take care of hyphenated names and call a function
'Me.PayTo = StrConv(Me.PayTo, vbProperCase)
Me.PayTo = fProperCase(PayTo.Text)
End Sub
Public Function fProperCase(ByVal vName As String)
'received from jasonlewis and modified by redrumba on 10/26/2007
'Returns ProperCase, including hyphenated names and names with an apostrophe
'(i.e. bob->Bob; smith-jones; Smith-Jones and O'neill -> O'Neill)
Dim vReturn
Dim vLeft
Dim vRight
Dim lHyphen As Long
Dim lApostrophe As Long
vReturn = Null
lHyphen = Nz(InStr(1, vName, "-", vbBinaryCompare), 0)
lApostrophe = Nz(InStr(1, vName, "'", vbBinaryCompare), 0)
If Len(vName) Then
If lHyphen Then
vLeft = Mid(vName, 1, lHyphen - 1)
vRight = Mid(vName, lHyphen + 1)
vReturn = StrConv(vLeft, Conversion:=vbProperCase) & "-" & StrConv(vRight, Conversion:=vbProperCase)
Else
If lApostrophe Then
vLeft = Mid(vName, 1, lApostrophe - 1)
vRight = Mid(vName, lApostrophe + 1)
vReturn = StrConv(vLeft, Conversion:=vbProperCase) & "'" & StrConv(vRight, Conversion:=vbProperCase)
Else
vReturn = StrConv(vName, Conversion:=vbProperCase)
End If
End If
End If
fProperCase = vReturn
End Function
I found the following code to help resolve hyphenated names, but need to tweak when you have more than one hyphen in a name
ie: the name is mary-joe jane > it works okay Mary-Joe Jane, but if the name is: mary-joe-jane smith it does Mary-Joe-jane Smith
I have a private sub and it calls the public function:
Private Sub PayTo_AfterUpdate()
' 09-16-20 tf attempt to have pay to name in proper case without manually doing it
' appears to work properly - yea!!
' does not handle hyphenated names
' found code to take care of hyphenated names and call a function
'Me.PayTo = StrConv(Me.PayTo, vbProperCase)
Me.PayTo = fProperCase(PayTo.Text)
End Sub
Public Function fProperCase(ByVal vName As String)
'received from jasonlewis and modified by redrumba on 10/26/2007
'Returns ProperCase, including hyphenated names and names with an apostrophe
'(i.e. bob->Bob; smith-jones; Smith-Jones and O'neill -> O'Neill)
Dim vReturn
Dim vLeft
Dim vRight
Dim lHyphen As Long
Dim lApostrophe As Long
vReturn = Null
lHyphen = Nz(InStr(1, vName, "-", vbBinaryCompare), 0)
lApostrophe = Nz(InStr(1, vName, "'", vbBinaryCompare), 0)
If Len(vName) Then
If lHyphen Then
vLeft = Mid(vName, 1, lHyphen - 1)
vRight = Mid(vName, lHyphen + 1)
vReturn = StrConv(vLeft, Conversion:=vbProperCase) & "-" & StrConv(vRight, Conversion:=vbProperCase)
Else
If lApostrophe Then
vLeft = Mid(vName, 1, lApostrophe - 1)
vRight = Mid(vName, lApostrophe + 1)
vReturn = StrConv(vLeft, Conversion:=vbProperCase) & "'" & StrConv(vRight, Conversion:=vbProperCase)
Else
vReturn = StrConv(vName, Conversion:=vbProperCase)
End If
End If
End If
fProperCase = vReturn
End Function