Name initials in Public Function

Hi experts,
I just got the answer from the previous ticket, capricorn1 show me the example, now I try to edit, but it seems not working.  My original question was:

Jane Doe   --   would like show j,d

Jane A. Doe  -- would like to show j,a,d

Jane B. Doe-Smith   -- would like to show j,b,D-S

John C. Smith-Jones, JR  -- would like to show j,c,s-m,jr

John Smith, JR  -- would like to show j,s,jr

now I want to do is

Jane Doe   --   would like show j. d

Jane A. Doe  -- would like to show j. a. d

Jane B. Doe-Smith   -- would like to show j. b. D-S

John C. Smith-Jones, JR  -- would like to show j. c. s-m, jr.

John Smith, JR  -- would like to show j. s, jr.

John Jones, III  - would like to show j. j, III.

thanks
db-Q-28163004.mdb
Who is Participating?

Commented:
use this

Function fGetInitials(strName As String) As String
Dim varName() As String, j As Integer, strInit As String, xName() As String
If strName & "" <> "" Then
varName = Split(strName, " ")

For j = 0 To UBound(varName)
If j > 2 Then
strInit = strInit & ", " & varName(3) & "."
Exit For
End If
xName = Split(varName(j), "-")
If UBound(xName) > 0 Then
strInit = strInit & ". " & Left(xName(0), 1) & "-" & Left(xName(1), 1)
Else
strInit = strInit + ". " + Left(varName(j), 1)
End If

Next
fGetInitials = Replace(Mid(strInit, 2), ". .", ". ")
End If

End Function
db-Q-28163004-Rev.mdb
0

Commented:
0

Author Commented:
Hi capricorn1, how can I put a space after the period?  I tried this but the first record has two period. also need a space before the JR or III something like

John C. Smith-Jones, JR  -- would like to show j. c. s-m, jr.
John Jones, III  - would like to show j. j, III.
db-Q-28163004-Rev.mdb
0

Author Commented:
I got the space for the JR question, but the fisrt record that doesn'r have middle initial still showing J..D instead J. D
0

Author Commented:
Thanks so much for your help capricorn1!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.