First Letter of Each Word

R

Rick_C

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
 
O

Ofer Cohen

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])
 
R

Rick_C

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
 
O

Ofer Cohen

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
 
Top