PC Review


Reply
Thread Tools Rate Thread

Building a SQL string

 
 
DZ
Guest
Posts: n/a
 
      17th Sep 2008
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
 
Reply With Quote
 
 
 
 
sfisher973
Guest
Posts: n/a
 
      18th Sep 2008


"DZ" wrote:

> 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

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with sql string building Jack Microsoft Access Queries 2 13th Nov 2009 11:14 PM
Building A string dmoney Microsoft Excel Programming 1 1st Oct 2009 05:15 AM
building a string Dave Microsoft Access VBA Modules 3 18th May 2008 09:46 PM
Is KeyValuePair<string,string>.ToString intended as serialization building block? Steve Richter Microsoft C# .NET 2 7th May 2007 09:34 PM
Building an SQL query string to include "&" as part of string Paul Microsoft Access VBA Modules 4 27th Aug 2003 09:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:52 AM.