Results 1 to 6 of 6
  1. #1
    Dutch1956 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    12

    Find first Capital letter in string

    Courtesy of Doug Steele, mvp, I found below Function which works great. It returns the position of the first capital letter in the string.
    However, I want it to return the first capital letter and not its position. Can you please tell me what I need to change in this Function?

    Function FirstCapital(InputString As String) As Long
    ' returns 0 if no capital found
    Dim lngFirstCapital As Long
    Dim lngLoop As Long
    Dim strCurrChar As String

    lngFirstCapital = 0
    For lngLoop = 1 To Len(InputString)
    strCurrChar = Mid$(InputString, lngLoop, 1)
    If Asc(strCurrChar) >= 65 And _
    Asc(strCurrChar) <= 90 Then
    lngFirstCapital = lngLoop
    Exit For
    End If
    Next lngLoop

    FirstCapital = lngFirstCapital



    End Function

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    FirstCapital = mid(InputString,lngFirstCapital,1)

  3. #3
    Dutch1956 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    12
    Thank you so much for the quick reply.
    Assuming that I replace you suggestion with FirstCapital = lngFirstCapital is causing a type mismatch. Please keep in mind that I am only a novice with ms access.

    Bert.

  4. #4
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    You have to change this part:
    Function FirstCapital(InputString As String) As Long

    to this:
    Function FirstCapital(InputString As String) As String

  5. #5
    Dutch1956 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Sep 2011
    Posts
    12
    Thank you so much Bob. It works amazing but you probably new that.You guys are amazing. Thanks again from rainy Wales in the United Kingdom.


    Bert.

  6. #6
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Quote Originally Posted by Dutch1956 View Post
    Thanks again from rainy Wales in the United Kingdom.
    You're welcome from normally rainy Portland, Oregon, USA (but we've had quite a few rain free days - okay, it has rained a little at night, but who counts that when you're sleeping )

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 05-30-2011, 09:38 AM
  2. filter name by letter
    By kbremner in forum Programming
    Replies: 3
    Last Post: 10-30-2010, 07:48 PM
  3. capital letters
    By accesshelp in forum Forms
    Replies: 1
    Last Post: 07-14-2010, 12:37 PM
  4. Month to return in Capital Letters
    By Alex Motilal in forum Queries
    Replies: 3
    Last Post: 01-09-2010, 05:19 AM
  5. From letter from a report
    By LANCE in forum Reports
    Replies: 4
    Last Post: 07-04-2009, 09:32 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums