If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > first letter of each word from a phrase

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Jun 2002
Posts: 173
first letter of each word from a phrase

Is there any kind of loop command that will extract the first letter from each word in a phrase. I have a text box that when a user enters info I need the initials of each word to get entered into another.
Reply With Quote
  #2 (permalink)  
Old
Registered User
 
Join Date: Mar 2003
Location: UK
Posts: 71
dim arr() as string

arr() = split(phrase, " ")

for n = 0 to noofwords

firstletterofword = left(arr(n), 1)
n = n+1

next
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
Join Date: Jun 2002
Posts: 173
Sorry, I'm a bit of a newby. Could you explain it a bit more. If I have a form linked to a table with two fields, one called text1, one called initials, how would I set it up. I'd like to have the user enter the phrase into text1 and then on the off focus command the initials would get entered into the initials text box.
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
Join Date: Mar 2003
Location: UK
Posts: 71
ok.
so you need to put the following code into the lostfocus event on the first text box.

Code:
Dim str1 As String 'String 1
Dim str2 As String 'String 2
Dim arr() As String 'Array to put contents of sting in when split into seperate words
Dim n As Variant 'Used to represent each word and they are used

str1 = Me.Text1.Value 'Puts contents of text bow 1 into first string

arr() = Split(str1, " ") 'Splits the string into words, using the " " seperator

For Each n In arr() 'For each of the words in the collection
    str2 = str2 & Left(n, 1) & " " 'adds a space and the first letter of each word
Next n

Me.Text2.Value = str2

Last edited by emma_com; 10-01-03 at 12:32.
Reply With Quote
  #5 (permalink)  
Old
Registered User
 
Join Date: Jun 2002
Posts: 173
I forgot to mention that I'm using Access97. Is the split function available. It errors out on it.
Reply With Quote
  #6 (permalink)  
Old
Registered User
 
Join Date: Aug 2003
Location: SW Ohio
Posts: 198
My suggestion is that you use the InStr() function (ref help for details) and look for spaces. Do it on the Instr() value plus 1 and a Do Loop. The code below is designed to strip dashes out of a Tax ID number, but you can do something similar to strip the the first letters on spaces.


Do Until RSTCLBorrTIN.EOF
TCLTin = RSTCLBorrTIN!BTAXID
Debug.Print I & ": " & TCLTin
If IsNull(TCLTin) = False And TCLTin <> "" Then
Do While InStr(1, TCLTin, "-", vbTextCompare) <> 0
TCLTin = Left(TCLTin, (InStr(1, TCLTin, "-", vbTextCompare) - 1)) & _
Right(TCLTin, Len(TCLTin) - (InStr(1, TCLTin, "-", vbTextCompare)))
Debug.Print I & ": " & TCLTin
Loop
End If
If EZTin = TCLTin Then
CurrBorrNum = RSTCLBorrTIN!BNUMBER
RSTCLBorrTIN.Close
Exit Do
End If
RSTCLBorrTIN.MoveNext
Loop
__________________
Jim P.

Supoorting Oracle, MSSQL7, Sybase 8, & Pervasive. Confusion Reigns
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On