Results 1 to 4 of 4
  1. #1
    Crawfordrider33 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2015
    Posts
    5

    Update Query SQL Code Help!!!

    Hello,



    I'm trying to right an update query that will look at a column of names and change some of the name that are listed as Smith, John to John Smith. The query I'm using is listed below:

    UPDATE [1 - Closed Loan Rpts - Debriefs NEW]
    SET [1 - Closed Loan Rpts - Debriefs NEW].Broker = StrConv(Right$([1 - Closed Loan Rpts - Debriefs NEW].Broker,Len([1 - Closed Loan Rpts - Debriefs NEW].Broker)-InStr(1,[1 - Closed Loan Rpts - Debriefs NEW].Broker,",")-1) & " " & Left$([1 - Closed Loan Rpts - Debriefs NEW].Broker,InStr(1,[1 - Closed Loan Rpts - Debriefs NEW].Broker,",")-1),3);

    The issue I'm experiencing is that when I run the query it deletes all the names in the row except for the names that are listed as Smith, John. I only want it to change those names and leave the rest as is.

    PLEASE HELP!!!

    Thank you!

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You need to add Criteria to the query so that it only selects the names you wish to change.

    A simple way to get this is to create a simple Select query, and play around with adding Criteria until you getting it selecting just the records you want to change. Then apply that same criteria to your Update Query here.

  3. #3
    Crawfordrider33 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2015
    Posts
    5
    Thanks Joe M! Unfortunately there a over 2000 different names in the data set. Is there anyway to apply an if statement to the update query that will only grab names with the "," in it? My ultimate goal is to write a query that will only change the names with the "," and just leave the rest be!

    Thank you!

  4. #4
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    Sure. Just have Criteria like this:
    WHERE InStr(1,[NameField],",")>0;
    which checks to see if some field ("NameField" in this example) contains a comma.

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

Similar Threads

  1. Hello Everyone!! UPDATE query VBA Code
    By Jllera in forum Programming
    Replies: 12
    Last Post: 03-06-2015, 08:46 PM
  2. Replies: 2
    Last Post: 06-28-2013, 12:58 PM
  3. Update Query by VBA code
    By ice051505 in forum Programming
    Replies: 10
    Last Post: 02-25-2013, 10:49 AM
  4. Automatically Update Query Parameter w/ Code
    By benthamq in forum Programming
    Replies: 2
    Last Post: 08-20-2011, 03:46 PM
  5. Before Update code
    By jms in forum Forms
    Replies: 1
    Last Post: 03-10-2011, 11:28 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