Extract the first letter of each word

G

Guest

Hi all, does anyone happen to know how we can extract the first letter of each word in a field to form a new abbreviation in Access? Thanks!
 
G

Graham R Seach

Ming,

Public Function GetAbbrevs(sText As String) As String
Dim sTmp As String

sText = Trim(sText)

Do While InStr(1, sText, " ") > 0
sTmp = sTmp & Left(sText, 1)
sText = Mid(sText, InStr(1, sText, " ") + 1)
Loop

GetAbbrevs = sTmp & Left(sText, 1)
End Function

If you need to call this from a query, use the following syntax:
SELECT field1, field2, GetAbbrevs(field3) As somename FROM tblMyTable

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Ming said:
Hi all, does anyone happen to know how we can extract the first letter of
each word in a field to form a new abbreviation in Access? Thanks!
 

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

Top