Basic string Question

  • Thread starter Thread starter Lee Taylor-Vaughan
  • Start date Start date
L

Lee Taylor-Vaughan

How do i get a text box to show the first initial for each word

for example Wayne General Hospital = WGH (no spaces)

I tried fiddling with this but i cant get it to work.


thanks

Lee
 
I've done this using a function.
Here's the code...

Public Function Initials(StringData As String) As String
Dim TempInitials As String
Dim StringLength As Integer
Dim Counter As Integer

TempInitials = ""
StringLength = Len(StringData)

'create initials string
If StringLength > 0 Then
TempInitials = Left$(StringData, 1)
For Counter = 2 To StringLength
If Mid(StringData, Counter, 1) = " " Then
TempInitials = TempInitials & Mid(StringData, Counter + 1, 1)
End If
Next
End If

'convert to upper case
Initials = UCase(TempInitials)

End Function

You need to paste this code into a module. A call could be
Initials(YourFieldName)

HTH
Sam
 
Works Great, thanks.....

Lee


Sam said:
I've done this using a function.
Here's the code...

Public Function Initials(StringData As String) As String
Dim TempInitials As String
Dim StringLength As Integer
Dim Counter As Integer

TempInitials = ""
StringLength = Len(StringData)

'create initials string
If StringLength > 0 Then
TempInitials = Left$(StringData, 1)
For Counter = 2 To StringLength
If Mid(StringData, Counter, 1) = " " Then
TempInitials = TempInitials & Mid(StringData, Counter + 1, 1)
End If
Next
End If

'convert to upper case
Initials = UCase(TempInitials)

End Function

You need to paste this code into a module. A call could be
Initials(YourFieldName)

HTH
Sam
 
Back
Top