Building a SQL string

D

DZ

The project manager want the user to select names using checkboxes.
Then run a report with those names as filter.

I was thinking of accomplishing this by using DAO to loop through the
records and a building a WHERE clause to tack onto a query with something
like the following


If ckFilter = -1 then
strWhere = strWhere & " Or Name = '" & rs(Name).Value & "'"
End if

I was just checking if anyone out there might use different method to
filter a report based on checked off items.

Thanks for any ideas
 
S

sfisher973

DZ said:
The project manager want the user to select names using checkboxes.
Then run a report with those names as filter.

I was thinking of accomplishing this by using DAO to loop through the
records and a building a WHERE clause to tack onto a query with something
like the following


If ckFilter = -1 then
strWhere = strWhere & " Or Name = '" & rs(Name).Value & "'"
End if

I was just checking if anyone out there might use different method to
filter a report based on checked off items.

Thanks for any ideas

Well, from the rs(name) syntax it look like you have a table of names and
checkboxes that you're using to select the names from... If that is the case
then your where clause could just be a sub-query as in:

SQL = "SELECT ReportData FROM ReportDataTableQuery WHERE
ReportDataTableQuery.Name IN (SELECT UserName FROM NamesTable WHERE
CheckFilter = -1)

IN can also be used if you just have a finite number of names instead of
OR'ing them together you can instead build a string of comma separated names

so that the WHERE would look like: "WHERE Name IN ('Jones','Smith','Johnson')

Look up the IN Operator in Microsoft Access Help (Not VBA Help) Also
'Subqueries'

Hope this helps...
-Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top