Results 1 to 4 of 4
  1. #1
    desertfx41 is offline Novice
    Windows 8 Access 2013
    Join Date
    Jun 2015
    Posts
    3

    Updating fields based on location of other fields

    Good morning everybody. I am trying to subtract amounts from one out of five possible fields based on the location of another piece of data using an Access query. Here's a better explanation:

    Table to Update: ProductData
    Field Names-Location1, Location2, Location3, Location4, Location5, Quantity1, Quantity2, Quantity3, Quantity4, Quantity5

    Table used for the update: QtyUpdate
    Field Names-Location, Quantity

    If a given location in the QtyUpdate.Location field falls in ProductData.Location2, then I need to subtract QtyUpdate.Quantity from the corresponding quantity field ProductData.Quantity2


    My guess was to use an IIf statement something like this: IIf(([ProductData].[Location1] CONTAINS [QtyUpdate].[Location], [ProductData].[Quantity1]-[QtyUpdate].[Quantity])) Or IIf(([ProductData].[Location2] CONTAINS [QtyUpdate].[Location], [ProductData].[Quantity2] - [QtyUpdate].[Quantity].........etc.

    Any help would be appreciated, thank you.

  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,967
    ProductData table is not a normalized structure. Since the tables cannot be joined in query, would need to use DLookup() domain aggregate function. The conditional expression will be far too long and cumbersome for query and I expect this will require a custom VBA function.

    CONTAINS is not an operator in VBA. Use = sign or InStr() or LIKE and wildcard.

    Ideally, aggregate data (quantity balance) would not be saved into table. Save transaction records of product in and product out and then calculate balance when needed.
    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
    desertfx41 is offline Novice
    Windows 8 Access 2013
    Join Date
    Jun 2015
    Posts
    3
    Thank you for the reply. Yes I noticed in my research this morning that CONTAINS is not an operator. I don't know any VBA and have only been working with SQL for a few months for Access queries. Keeping a transaction record would be nice. I will see what I can come up with using the condition types you mentioned.

  4. #4
    desertfx41 is offline Novice
    Windows 8 Access 2013
    Join Date
    Jun 2015
    Posts
    3
    The simple solution to this was to create five separate update queries that updated each quantity field and then a macro to run them all at once. Perhaps not the most elegant solution but it works.

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

Similar Threads

  1. Replies: 1
    Last Post: 02-27-2015, 05:03 PM
  2. Replies: 1
    Last Post: 06-20-2013, 05:06 PM
  3. Replies: 1
    Last Post: 07-06-2012, 05:32 PM
  4. Replies: 12
    Last Post: 05-07-2012, 12:41 PM
  5. Auto Updating Fields
    By allstar45 in forum Queries
    Replies: 3
    Last Post: 03-05-2012, 08:51 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