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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top