Results 1 to 3 of 3
  1. #1
    Thompyt is offline Expert
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2014
    Location
    El Paso, TX
    Posts
    862

    Find whole word and replace with Acronyms

    tblRoles:


    Field1 = Roles


    tbleAcronyms:
    Field1 = Names
    Field2 = Acros

    What I want to do is search for Like items in tblRoles.Roles with Like "[Names]" and replace where true with tblAcronyms.Acros and update
    tblRoles.Roles.

    Its easy if I have to do manually, but I would like to automate so I don't have to find and replace 15 or so items after each time I import a new excel into a table.

    Would it be something along the lines of:
    Replace("Names", .....

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I would try an update query that joins the two tables on that field.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    accesstos's Avatar
    accesstos is offline Expert
    Windows XP Access 2007
    Join Date
    Dec 2018
    Location
    Greece
    Posts
    551
    Maybe you need a code like bellow:

    Code:
    Option Compare Database
    Option Explicit
    
    Private Const cstrSQL As String = "UPDATE tblRoles SET  [Roles] = Replace([Roles],'$n$','$a$') WHERE (instr(1,[Roles],'$n$',1)>0);"
    
    Sub ReplaceNamesWithAcronyms()
        Dim strSQL As String
        
        With CurrentDb.OpenRecordset("tbleAcronyms", dbOpenForwardOnly)
            While Not .EOF
                strSQL = Replace(cstrSQL, "$n$", ![Names])
                strSQL = Replace(strSQL, "$a$", ![Acros])
                .MoveNext
                CurrentDb.Execute strSQL, dbFailOnError
            Wend
            .Close
        End With
    End Sub
    Do Not Use It in your original database!!!
    Give it a try in a copy of your project.

    Happy new year! :-)

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

Similar Threads

  1. Replies: 3
    Last Post: 04-30-2015, 11:46 AM
  2. VBA to find/replace text in word document
    By Goodge12 in forum Programming
    Replies: 1
    Last Post: 07-16-2014, 01:23 PM
  3. Replies: 1
    Last Post: 05-31-2013, 10:10 AM
  4. Multiple Acronyms for Same Name
    By giblets in forum Access
    Replies: 14
    Last Post: 07-19-2012, 01:43 PM
  5. find and replace
    By rohini in forum Access
    Replies: 7
    Last Post: 05-17-2012, 05:23 AM

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