Remove a Middle Initial and Period from Field

Posted on 2009-04-15
Last Modified: 2013-11-27
I have a Field name Employee_FirstName with thousands of values.  I need a Function that removes the Middle initial and Period if it is present.  Each Middle initial is followed by a period. Some people just have their first name without a MI and period.

Sample Data
Oscar L.  should be Oscar
Tammy H. should be Tammy
Jo Anne should remain Jo Anne

How can I accomplish this with a Function and an expression in a query?   Thanks
Question by:quizzer
    1 Comment
    LVL 92

    Accepted Solution

    You can add the UDF below, and then use it like this:

    SELECT Employee_FirstName, RegExpReplace(Employee_FirstName, " [A-Z]\.", "",True, False) AS FirstOnly
    FROM SomeTable
    Function RegExpReplace(LookIn As String, PatternStr As String, Optional ReplaceWith As String = "", _
        Optional ReplaceAll As Boolean = True, Optional MatchCase As Boolean = True) 
        ' This function uses Regular Expressions to parse a string, and replace parts of the string
        ' matching the specified pattern with another string.  The optional argument ReplaceAll controls
        ' whether all instances of the matched string are replaced (True) or just the first instance (False)
        ' By default, RegExp is case-sensitive in pattern-matching.  To keep this, omit MatchCase or
        ' set it to True
        ' If you use this function from Excel, you may substitute range references for all the arguments
        Static RegX As Object
        If RegX Is Nothing Then Set RegX = CreateObject("VBScript.RegExp")
        With RegX
            .Pattern = PatternStr
            .Global = ReplaceAll
            .IgnoreCase = Not MatchCase
        End With
        RegExpReplace = RegX.Replace(LookIn, ReplaceWith)
        Set RegX = Nothing
    End Function

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
    'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
    Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
    In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now