Results 1 to 4 of 4
  1. #1
    COM34 is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Apr 2012
    Posts
    2

    Post Selecting a row's highest option and its associated code

    I have an MS Access table that contains colour codes and their relevant percentage with reference to particular products. Each product can be made up of up to 3 colours and I am trying to determine the most used colour for each product - so far I can determine the percentage of the highest colour (using a MaxOfList VBA module), but am unable to associate it with the actual colour.



    Table example:
    ProductID ColourCode1 Colour1Proportion ColourCode2 Colour2Proportion ColourCode3 Colour3Proportion Highest
    1 Col034 100 100
    2 Col023 25 Col241 50 Col065 25 50
    3 Col024 17 Col211 23 Col360 60 60

    So as an example, product 001 would return Col034, product 002 would return Col241 and product 003 would return Col360.

    The colour codes are as they stand i.e. they do not refer to another table to return a 'real-world' colour, and there isn't a rule on the order by which the the codes should be entered. This is a fully normalised table.

    Essentially I need something that performs a Vlookup on the Highest column, and returns the value which is 1 field to the left of the result. Unfortunately a dlookup won't help me here.

    I've toyed with the idea of creating temporary tables for each listed block of colour-related columns (e.g. ColourCode1 and ColourProportion1 in one table, ColourCode2 and ColourProportion2 in another etc) and trying to sort these for each ProductID, but I don't think that would help.

    Any ideas / pointers would be greatly appreciated!

  2. #2
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Welcome to the forum!

    First, and contrary to your statement that the table is fully normalized -- it is not.

    Each product can be made up of up to 3 colours
    What you describe is a one-to-many relationship which requires a related table to hold the 3 colors pertinent to a product. Each color would be a record not a field in that table.

    tblProducts
    -pkProductID primary key, autonumber
    -ProductNumber

    tblProductColors
    -pkProdColorID primary key, autonumber
    -fkProductID foreign key to tblProducts
    -colorcode
    -colorproportion

    Now if a color can be used on more than one product, you have another one-to-many relationship. When you have 2 one-to-many relationships between the same two entites (products and colors in this case) you need a junction table. So the question, is each color you mention unique to only 1 product?

  3. #3
    COM34 is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Apr 2012
    Posts
    2
    Thanks, jzwp11 - I see what you mean. Rookie mistake - each colour is not unique so this would involve a 1-m relationship.

    I have since discovered that this table is actually a derived table (I'm not sure if this is the correct terminology - it definitely isn't a base table anyway) - this data comes in via a read-only ODBC link from an Oracle database. Will have a look through all the other tables in the hope that there is a normalised set somewhere.

    In the meantime, someone has provided me with a query that identifies the highest apportioned code based on this one table - even though it takes a while run on 10k plus records, it is better than nothing. Hopefully I'll find a normalised set in Oracle!

    Thanks for your input

  4. #4
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Glad to hear that you have a solution for the immediate issue and that you are looking into the table structure further.

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

Similar Threads

  1. Selecting highest value across several fields
    By megabrown in forum Queries
    Replies: 19
    Last Post: 10-28-2014, 01:16 AM
  2. Option Buttons & After Update code - Linked
    By Norbayah in forum Forms
    Replies: 2
    Last Post: 02-28-2012, 09:52 PM
  3. Selecting the State Code
    By TheBigMaple in forum Queries
    Replies: 1
    Last Post: 03-30-2011, 05:34 PM
  4. VB code for sending email through Option Group?
    By getdpt in forum Programming
    Replies: 0
    Last Post: 08-23-2009, 03:59 PM
  5. VBA Code in Access w/ option buttons
    By WebKiid in forum Access
    Replies: 1
    Last Post: 07-16-2009, 12:20 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