Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17
  1. #16
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: sql - using AND in child table (2000/XP)

    Sorry about the delay, the Lounge went away for a few hours.

    I have attached a modified version of the database. I added autonumber primary keys to the "main" tables, and removed the autonumber fields from the "junction" tables tblProduct and tblRegion.

    The central part of the code is now as follows:

    If Not IsNull(Me.cmbSearch) Then
    strWhere1 = " AND CompanyID In (SELECT CompanyID FROM " & _
    "tblRegion WHERE RegionID=" & Me.cmbSearch & ")"
    End If

    ' Loop through the selected items in the list box
    For Each varItem In Me.List2.ItemsSelected
    ' Add part to strWhere2
    strWhere2 = strWhere2 & " AND CompanyID In " & _
    "(SELECT CompanyID FROM tblProduct " & _
    "WHERE ProductID=" & Me.List2.ItemData(varItem) & ")"
    Next varItem

    strWhere = strWhere1 & strWhere2
    If Not strWhere = "" Then
    strWhere = Mid(strWhere, 6)
    End If

    I had to guess what you wanted the query to do.
    Attached Files Attached Files

  2. #17
    New Lounger
    Join Date
    May 2008
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: sql - using AND in child table (2000/XP)

    Thanks, that is exactly what i wanted.

Page 2 of 2 FirstFirst 12

Posting Permissions

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