First Letter of Each Word

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I go about capturing just the first letter of each name so that John
Smith would look like JS.

The code that I am using is Left([Name], 1) which works great if there is
only one name.

Thanks in advance for the help.

Rick
 
Copy this function into a Module
****************************
Function GetInit(MyName As String)
Dim I As Integer

GetInit = Left(MyName, 1)
For I = 2 To Len(MyName)
If Mid(MyName, I, 1) = " " Then
GetInit = GetInit & Mid(MyName, I + 1, 1)
End If
Next I
End Function
**************************
You can use this function either in the report RecordSource or as a
ControlSource in a text box in the report

=GetInit([FullNameFieldName])

Or a new field in the query

InitialName: GetInit([FullNameFieldName])
 
Thank You!!!

It works great...

Rick


Ofer Cohen said:
Copy this function into a Module
****************************
Function GetInit(MyName As String)
Dim I As Integer

GetInit = Left(MyName, 1)
For I = 2 To Len(MyName)
If Mid(MyName, I, 1) = " " Then
GetInit = GetInit & Mid(MyName, I + 1, 1)
End If
Next I
End Function
**************************
You can use this function either in the report RecordSource or as a
ControlSource in a text box in the report

=GetInit([FullNameFieldName])

Or a new field in the query

InitialName: GetInit([FullNameFieldName])

--
Good Luck
BS"D


Rick_C said:
How can I go about capturing just the first letter of each name so that John
Smith would look like JS.

The code that I am using is Left([Name], 1) which works great if there is
only one name.

Thanks in advance for the help.

Rick
 
One more thing, to improve the function incase there are two spaces between
then names

Function GetInit(MyName As String)
Dim I As Integer

GetInit = Left(MyName, 1)
For I = 2 To Len(MyName)
If Mid(MyName, I, 1) = " " Then
If Mid(MyName, I + 1, 1) <> " " Then
GetInit = GetInit & Mid(MyName, I + 1, 1)
End If
End If
Next I
End Function


--
Good Luck
BS"D


Rick_C said:
Thank You!!!

It works great...

Rick


Ofer Cohen said:
Copy this function into a Module
****************************
Function GetInit(MyName As String)
Dim I As Integer

GetInit = Left(MyName, 1)
For I = 2 To Len(MyName)
If Mid(MyName, I, 1) = " " Then
GetInit = GetInit & Mid(MyName, I + 1, 1)
End If
Next I
End Function
**************************
You can use this function either in the report RecordSource or as a
ControlSource in a text box in the report

=GetInit([FullNameFieldName])

Or a new field in the query

InitialName: GetInit([FullNameFieldName])

--
Good Luck
BS"D


Rick_C said:
How can I go about capturing just the first letter of each name so that John
Smith would look like JS.

The code that I am using is Left([Name], 1) which works great if there is
only one name.

Thanks in advance for the help.

Rick
 
Back
Top