Results 1 to 6 of 6
  1. #1
    alex1888 is offline Novice
    Windows 8 Access 2013
    Join Date
    May 2015
    Posts
    10

    Replacing expression in table using VBA

    Hello,

    My question is a bit complicated.

    For the purpose of the question, let's take for example the following table:

    Click image for larger version. 

Name:	exmp1.PNG 
Views:	9 
Size:	14.1 KB 
ID:	20905

    I want, using VBA, to find the entry ID= 2 and to replace the expression "United States of America" under "Description" with the expression "USA". How can i do it?

    I'd love your help.


    1-Q

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    CurrentDb.Execute "UPDATE tablename SET Description = Replace([Description], 'United States of America', USA' WHERE ID = 2"

    Be aware the Replace function could throw error if the Description field is Null. The WHERE clause is not actually necessary but could make the action run faster as well as not encounter any Nulls.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    alex1888 is offline Novice
    Windows 8 Access 2013
    Join Date
    May 2015
    Posts
    10
    Thank you very much !!

  4. #4
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    you've missed a quote and bracket

    Replace([Description], 'United States of America', 'USA') WHERE

    sort of thing I usually do.....

  5. #5
    alex1888 is offline Novice
    Windows 8 Access 2013
    Join Date
    May 2015
    Posts
    10
    Yeah I figured it out


    Thank you very much you helped me a lot.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Ooops. Except that was a missing paren. Brackets: []; Braces: {}

    But glad you have it working.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replacing ALL Null values in a Table
    By jhlee2222 in forum Queries
    Replies: 16
    Last Post: 01-03-2014, 11:33 AM
  2. Replacing table in Access Via Excel
    By Bob Blooms in forum Access
    Replies: 2
    Last Post: 09-01-2012, 02:02 PM
  3. Replies: 4
    Last Post: 08-14-2012, 07:14 AM
  4. Replacing data in Table
    By JackT in forum Import/Export Data
    Replies: 1
    Last Post: 08-23-2010, 10:34 AM
  5. Replies: 0
    Last Post: 09-17-2009, 12:21 PM

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