Results 1 to 6 of 6
  1. #1
    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.

  2. #2
    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

  3. #3
    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.

  4. #4
    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 13:32.

  5. #5
    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.

  6. #6
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •