Results 1 to 5 of 5
  1. #1
    rohini is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    41

    update query

    how do you use update query to change a part of the data in any cell in a table.



    for example:
    i want to change 'i love mangoes' to 'i love apple' i.e. i am changing a part of text

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Can run Find/Replace dialog on the table or try:

    UPDATE table SET fieldname = Replace(fieldname, 'mangoes', 'apples')

    Use the query designer to build and save query object then use code to run. If you want to automate this with user input for the text change, how do you want users to provide the inputs? By query input parameters or by reference to controls on a form?

    The SQL statement can also be built and run entirely with VBA code and executed with a button Click event, like:

    CurrentDb.Execute "UPDATE table SET fieldname = Replace(fieldname, '" & Me.textboxOldText & "', '" & Me.textboxNewText & "'")
    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
    rohini is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    41
    what is basically the case is that i have a table
    one column with names of people and other with "i love mangoes", "she loves mangoes", "he loves mangoes", etc
    where all of this has to be changed to ""i love apples", "she loves apples", "he loves apples", etc
    dint really get what you wrote above..

  4. #4
    rohini is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Feb 2012
    Posts
    41
    hey

    the input table is:
    name fruit
    joey joey likes mangoes
    rachel rachel likes mangoes
    monica monica likes mangoes
    ross ross likes pineapple
    emily emily likes mangoes


    output should be:

    name fruit
    joey joey likes apples
    rachel rachel likes apples
    monica monica likes apples
    ross ross likes pineapple
    emily emily likes apples


    hope that clarifies everything!

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Why are you duplicate saving the name and 'likes' anyway? Just save the fruit and then build the sentence with an expression in a textbox whenever needed.

    My suggestion is to:

    1. build a form where the 'old' and 'new' values can be input into textboxes

    2. build an UPDATE query that refers to the textboxes as parameters

    3. run the UPDATE query either as an Access query object or with the VBA command I show

    Building the query with designer is basic Access functionality.
    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. Replies: 4
    Last Post: 11-10-2011, 03:41 PM
  2. Replies: 2
    Last Post: 09-21-2011, 01:30 PM
  3. Replies: 1
    Last Post: 08-19-2011, 12:16 PM
  4. Update 2 tables with one Update Query
    By Douglasrac in forum Queries
    Replies: 4
    Last Post: 04-14-2011, 08:33 AM
  5. Update Query- selective update?
    By stephenaa5 in forum Queries
    Replies: 1
    Last Post: 10-29-2009, 11:15 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