Consulting

Results 1 to 3 of 3

Thread: Create Unduplicated Combinations

  1. #1

    Create Unduplicated Combinations

    Howdy,

    I'll just try and explain what I am looking for. Let's say I have a field called 'Flavor' with 10 flavors in it. I want to create all unique combinations against itself (Chocolate/Vanilla, Chocolate/Strawberry, etc.). This is a simple cartesian product of 100 combinations (10x10) created by adding my Flavor table to a query twice and not linking them. I can even get rid of unnecessary dupe combos like Chocolate/Chocolate. However, combos like Chocolate/Vanilla and Vanilla/Chocolate are technically the same thing but come up when I run my query. How can I get rid of these combos as well?

    Thanks

  2. #2
    VBAX Master CreganTur's Avatar
    Joined
    Jan 2008
    Location
    Greensboro, NC
    Posts
    1,675
    Location
    The only idea I can give you is to create a loop that will combine all the names and have a module level array. Within the loop you will check the array to see if the combination exists. If no, then add to array. If yes, then do not add to array.

    I could come up with a much more elegant solution if only VBA allowed Lists.
    -Randy Shea
    I'm a programmer, but I'm also pro-grammar!
    If your issue is resolved, please use Thread Tools to mark your thread as Solved!

    PODA (Professional Office Developers Association) | Certifiable | MOS: Access 2003


  3. #3
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    447
    Location
    You could add a unique number column to your flavors table ... I used an autonumber primary key, flavor_id ... then use a query similar to this to return the combinations you want:
    [vba]SELECT f1.flavor_name, f2.flavor_name
    FROM Flavors AS f1, Flavors AS f2
    WHERE (f1.flavor_id / f2.flavor_id) > 1;
    [/vba]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •