Lowercase last names

gojets1721

Registered User.
Local time
Yesterday, 23:45
Joined
Jun 11, 2019
Messages
430
Curious if someone could help with this issue. Couldn't find a specific guide online to assist.

I have a table of last names that are entirely uppercase. I want make them proper text. I'm using the following function in an update function that works well:

Code:
StrConv ( [CustomerLastName], 3 )

The problem is I want it recognize apostrophes and dashes, and capitalize the succeeding letter. See the below table for examples:

Before Update​
After Update​
Ideal​
O'BRYANO'bryanO'Bryan
SMITH-JONESSmith-jonesSmith-Jones

Is there a way to add onto to / change this code so that any letter after an '-' or an ' ' ' is also capitalized?
 
Try

StrConv(CustomerLastName, vbProperCase) 'convert to proper case
 
Look at that:
Code:
Sub words()
    Dim sText As String
    Dim oMC As Object
    Dim i As Long
    Dim sResult As String

    sText = "O'BRYAN, SMITH-JONES"
    Set oMC = RegExMatchCollection(sText, "(\b.+?\b)")
    If oMC.Count > 0 Then
        For i = 0 To oMC.Count - 1
            'Debug.Print oMC(i)
            sResult = sResult & StrConv(oMC(i), 3)
        Next
    End If
    Debug.Print sResult
End Sub

'------------------------------------------------------------------------
' Return
O'Bryan, Smith-Jones
Link to RegExMatchCollection
 
@mike60smart vbProperCase IS 3. In VBA, I would always use the enumeration but in a query, you need to use the number.
 
Look at that:
Code:
Sub words()
    Dim sText As String
    Dim oMC As Object
    Dim i As Long
    Dim sResult As String

    sText = "O'BRYAN, SMITH-JONES"
    Set oMC = RegExMatchCollection(sText, "(\b.+?\b)")
    If oMC.Count > 0 Then
        For i = 0 To oMC.Count - 1
            'Debug.Print oMC(i)
            sResult = sResult & StrConv(oMC(i), 3)
        Next
    End If
    Debug.Print sResult
End Sub

'------------------------------------------------------------------------
' Return
O'Bryan, Smith-Jones
Link to RegExMatchCollection
Thanks. How would I incorporate this into an update query?
 
Code:
Public Function ProperCaseEBS(sText As Variant) As String
   If Not IsNull(sText) Then
      Dim oMC As Object
      Dim i As Long
      Dim sResult As String
      Set oMC = RegExMatchCollection(sText, "(\b.+?\b)")
       If oMC.Count > 0 Then
           For i = 0 To oMC.Count - 1
            sResult = sResult & StrConv(oMC(i), 3)
        Next
      End If
      ProperCaseEBS = sResult
   End If
End Function

Update SomeTable SET CustomerLastName = ProperCaseEBS([CustomerLastName])
 

Users who are viewing this thread

Back
Top Bottom