Results 1 to 5 of 5
  1. #1
    opopanax666 is offline Novice
    Windows 7 Access 2007
    Join Date
    Aug 2010
    Posts
    27

    Recordset loop & change values (kinda...)

    Hi everybody,



    I have a table "tblProduced" which stores our produced goods (duh), along with a Product_ID got from "tblProducts" (which contains about 120 products). An "illuminated" spirit within the company decided to change this product list. To cut a long story short, I'm stuck having to change all the old Product_ID's in "tblProduced" to the new ones (trust me, I looked at it from all angles, and this is the only way)...

    I have already set up a table ("tblConversion") listing the old ID's and respective new ID's.

    I can't use an update query (120 values to be checked), but I was thinking I could use a recordset loop that checks the conversion table for every record in "tblProduced", and updates that value with the corresponding new value out of "tblConversion".

    The problem is that I'm no good at recordsets, and the problem is too specific to find any help on the net. So I turn to you guys and girls for any help setting this up...

    TIA!

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Please see my next post

  3. #3
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Is Product_ID in tblProducts an autonumber key field? I assume that it is not. Is Product_ID the primary key of tblProducts? I assume that it is. You will have to change the Product_ID in both tblProducts and tblProduced and any other table to which tblProducts is joined. I'm not sure why you say that you cannot use an update query. In either case, you will have to temporarily remove all of the joins to or from Product_ID of tblProducts and any other tables that reference Product_ID. Once you do that, you should be able to use your conversion table to make the updates. Once done, you will have to re-establish your relationships. First, I would make a backup copy of the database!


    The UPDATE query for tblProducts would look like this:

    UPDATE tblProducts INNER JOIN tblConversion ON tblConversion.OldProductID = tblProducts.Product_ID SET tblProducts.Product_ID = [tblConversion].[NewProductID];

    And for tblProduced the UPDATE query would look like this:

    UPDATE tblProduced INNER JOIN tblConversion ON tblConversion.OldProductID = tblProduced.Product_ID SET tblProduced.Product_ID = [tblConversion].[NewProductID];

  4. #4
    opopanax666 is offline Novice
    Windows 7 Access 2007
    Join Date
    Aug 2010
    Posts
    27
    Thank you so much for your solution. I don't use update queries that much, and I hadn't considered doing it like this. Thank you again!

  5. #5
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You're welcome.

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

Similar Threads

  1. a loop using vba to change control name
    By Chuck55 in forum Programming
    Replies: 4
    Last Post: 04-23-2012, 09:23 PM
  2. Double loop recordset
    By silverspr in forum Programming
    Replies: 7
    Last Post: 03-07-2012, 01:43 PM
  3. Loop through recordset
    By eliedebs in forum Programming
    Replies: 1
    Last Post: 01-11-2012, 12:26 AM
  4. Getting Values out of a recordset
    By theracer06 in forum Programming
    Replies: 6
    Last Post: 09-24-2010, 03:44 PM
  5. Bulk Email / Loop through recordset
    By smikkelsen in forum Forms
    Replies: 4
    Last Post: 07-12-2010, 06:59 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