Help constructing a query

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lauren quantrell

    #1

    Help constructing a query

    I have a table of contacts tblCon that includes customers and sales
    persons with the identity column ConID
    I have a table tblLinks that contains links between contacts. It looks
    like this:
    ID Customer Salesman
    1 123 678
    2 456 901
    3 789 901
    where 123, 456, 789, 678, 901 are the ConID from tblCon. Salemen can be
    assigned to more than one customer and customers can have more than one
    salesman.

    What I want to do is to create a contact detail form that includes a
    combobox.
    I want to populate the combobox so that when you open the combo box, it
    is populated only with customers or salesmen which are not already
    linked to the contact being viewed. For example, I open contact details
    for salesman 901 and the combo box would only include customer 123
    because 901 is already linked to 456 and 789.
    The combobox has to consider that 901 may not yet be linked to any
    customers and that it may be linked already to other customers that are
    irrelevant.
    I thought this was easy, and maybe it is, but I spent a lot of time
    trying to construct this without success.

  • pietlinden@hotmail.com

    #2
    Re: Help constructing a query

    <snip>
    What I want to do is to create a contact detail form that includes a
    combobox.
    I want to populate the combobox so that when you open the combo box, it
    is populated only with customers or salesmen which are not already
    linked to the contact being viewed.
    </snip>

    Can't you do that with a left join?

    SELECT ...
    FROM Contacts LEFT JOIN Salesmen ON ...
    WHERE ContactID IS NULL

    or something along those lines? Or are you trying to union the two
    sets together? If that's the case, you'd have one left join query for
    each set and then just UNION [ALL] to create one result set.

    Or did I misunderstand the question?

    if you can only populate the combo with Contacts XOR Salesmen, then I
    would have another combo that set the rowsource of the one in question
    through code.

    Not sure if my reading of your question is right, but I hope this at
    least points you in the right direction...

    Comment

    Working...