Results 1 to 5 of 5
  1. #1
    Ayiramala is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Dec 2014
    Location
    Kerala, India
    Posts
    74

    Question on creating an update query


    Hi,
    I am trying to create an update query where the field DivisionID needs to be updated. What I want is this: 1 should be updated to 7, 2 to 8,3 to 9, 4 to 10, 5 to 11, and 6 to 12, I know how to do it with a single value, and how to do it by entering a parameter. But is there a way to include ALL of the above within the query, so that running it once will update all the values?

    Any help is appreciated. Thanks.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    So you want to add 6 to each value? Why?

    UPDATE tablename SET DivisionID = DivisionID + 6

    Suggest you first test with a copy of the table.
    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
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Go to the query design view, and in the "Update To" row for the DivisionID, put DivisionID + 6. when you run the query, all DivisionID values will be incremented by 6.

    Just be careful not to run the query more than once!

  4. #4
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    Solution depends: If there aren't too many fields you want to update, I think it can be done in one query, but you will need criteria for each field, otherwise the update will propagate through all records of a field. This means you will need a criteria row in the design grid for each field - you cannot put them all on the same row. You only show 6 fields, but maybe you haven't said there are 66. Also, are the numbers text or numbers?
    Assuming they are numbers and you want to always add 6 (or is that a coincidence of your post?) then this will update each field that meets the criteria by adding six to the value in the row where the field is Val(n).

    Code:
    UPDATE [tblYourTable] SET [tblYourTable].Val1 = [Val1]+6, [tblYourTable].Val2 = [val2]+6, [tblYourTable].val3 = [val3]+6
    WHERE ((([tblYourTable].Val1)=1)) OR ((([tblYourTable].Val2)=2)) OR ((([tblYourTable].val3)=3));
    Note: two great answers posted before I was finished, otherwise, I probably would have bowed out. I totally missed the point that the values were in one field. I'll leave the answer in case it could be useful to somebody, sometime, in a galaxy far, far away...

  5. #5
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    One thing I should have mentioned -

    Is DivisionID being used in any relationships?

    If it is, and you don't have the relationships defined correctly, you could be facing all kinds of problems with related tables, problems which are not always evident, resulting in incorrect data.

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

Similar Threads

  1. Replies: 1
    Last Post: 01-25-2013, 10:34 AM
  2. Creating an Update/Append Query
    By Jray9242 in forum Import/Export Data
    Replies: 2
    Last Post: 04-23-2012, 06:31 PM
  3. Update Query Question
    By Profector in forum Queries
    Replies: 2
    Last Post: 10-13-2010, 09:24 AM
  4. Update Query Which Asks Question
    By jhillbrown in forum Access
    Replies: 3
    Last Post: 02-15-2010, 06:36 AM
  5. update query question
    By blusk06 in forum Queries
    Replies: 3
    Last Post: 05-30-2008, 05:55 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