Add function to AfterUpdate

MissaLissa

New Member
Joined
Jul 2, 2013
Messages
26
Hi Guru's

I'm using vbProperCase in a sub AfterUpdate. However, the vbProperCase does not take into consideration last names that have a hyphen or apostrophe. So, I found a function to solve the issue, but I'm not sure how to implement it. Can someone please walk me through this? Much appreciated.

current code:
Code:
Private Sub Applicant2_Last_Name_AfterUpdate()    
    Me.Applicant2_Last_Name = StrConv(Me.Applicant2_Last_Name, vbProperCase)
End Sub

Need to add the following function:
Code:
Public Function fProperCase(ByVal vName As String)   
   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
 
Last edited:

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hi,
try calling the function like this:

Code:
Private Sub Applicant2_Last_Name_AfterUpdate()
    Me.Applicant2_Last_Name.Text = fProperCase(Applicant2_Last_Name.Text)
End Sub

Dave
 
Upvote 0
The function can go in the same place as the form code, or more generally you might prefer to put it into a module so that it can be used in any form.
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,102
Members
452,379
Latest member
IainTru

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top