I am trying to build up filter to grab one piece of information (quote_id) and use that to populate a combobox. There are a few fields that can be used, Distributor, Builder, First line of address (haven't got to yet). I use a tickbox next to each field to selectively enable/disable portions of the query. Anyhow, here's my code as it stands.
when run, the rowsource contains a syntax error. I have created the complex version of the query, which shows up as
in the query editor. I am in parenthesis hell here, and I don't know how to get out.
Code:
oldSource = "SELECT DISTINCT h.quote_id"
oldSource = oldSource & " FROM HouseType AS h INNER JOIN quotations AS q ON h.quote_id = q.quote_id "
If Me.DistFilter = True Then
oldSource = oldSource & " LEFT JOIN companies AS c1 ON q.dist_id = c1.Comp_ID"
End If
If Me.BuildFilter = True Then
oldSource = oldSource & " LEFT JOIN companies AS c2 ON q.build_id = c2.Comp_ID"
End If
oldSource = oldSource & " WHERE h.design_production_no Is Not Null"
If Me.DistFilter = True Then
oldSource = oldSource & " AND Nz([c1].[Company], [q].[distributor]) LIKE [forms]![FindSE].[DistList]"
End If
If Me.BuildFilter = True Then
oldSource = oldSource & " AND Nz([c2].[Company], [q].[builder]) LIKE [forms]![FindSE].[BuildList] "
End If)
End If
oldSource = oldSource & " ORDER BY h.quote_id DESC;"
when run, the rowsource contains a syntax error. I have created the complex version of the query, which shows up as
Code:
SELECT DISTINCT q.quote_id
FROM ((housetype AS h INNER JOIN quotations AS q ON h.quote_id = q.quote_id) LEFT JOIN companies AS c2 ON q.build_id = c2.Comp_ID) LEFT JOIN companies AS c1 ON q.dist_id = c1.Comp_ID
WHERE (((h.design_production_no) Is Not Null) AND ((Nz([c1].[Company],[q].[distributor])) LIKE [forms]![FindSE].[DistList]) AND ((Nz([c2].[Company],[q].[builder])) LIKE [forms]![FindSE].[BuildList]));