Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Filter in Access- SQL


Filter in Access- SQL

Author
Message
sasansamani
sasansamani
SSC Rookie
SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)

Group: General Forum Members
Points: 31 Visits: 66
This is my sql query in access. However, I am not sure where I need to add or filter on District. District needs to equal 1.

open attachment

SELECT [Austin Police Department].Name, [Austin Police Department].Location, [Austin Police Department].[Phone Number], [Austin Police Department].District, [Austin Police Department].[Position Title]
FROM [Austin Police Department]
WHERE ((([Austin Police Department].Name) Like "*" & [Forms]![Austin Police Department- District 1]![txtSearch2] & "*")) OR ((([Austin Police Department].Location) Like "*" & [Forms]![Austin Police Department- District 1]![txtSearch2] & "*")) OR ((([Austin Police Department].[Phone Number]) Like "*" & [Forms]![Austin Police Department- District 1]![txtSearch2] & "*")) OR ((([Austin Police Department].District) Like "*" & [Forms]![Austin Police Department- District 1]![txtSearch2] & "*")) OR ((([Austin Police Department].[Position Title]) Like "*" & [Forms]![Austin Police Department- District 1]![txtSearch2] & "*"))
ORDER BY [Austin Police Department].District;
Attachments
2.JPG (7 views, 116.00 KB)
ProofOfLife
ProofOfLife
SSC Rookie
SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)

Group: General Forum Members
Points: 48 Visits: 9474
Hi

Because you have multiple criteria specified as OR criteria, you need to select District = 1 on each of those criteria.

There WHERE clause will then look something like the following:

WHERE
((([Austin Police Department].Name) Like "*" & [Forms]![Austin Police Department- District 1]![txtSearch2] & "*") AND [Austin Police Department].District = 1)
OR
((([Austin Police Department].Location) Like "*" & [Forms]![Austin Police Department- District 1]![txtSearch2] & "*") AND [Austin Police Department].District = 1)
OR
((([Austin Police Department].[Phone Number]) Like "*" & [Forms]![Austin Police Department- District 1]![txtSearch2] & "*") AND [Austin Police Department].District = 1)
OR
((([Austin Police Department].District) Like "*" & [Forms]![Austin Police Department- District 1]![txtSearch2] & "*"))
OR
((([Austin Police Department].[Position Title]) Like "*" & [Forms]![Austin Police Department- District 1]![txtSearch2] & "*") AND [Austin Police Department].District = 1)

I hope this is clear enough.

Cheers
sasansamani
sasansamani
SSC Rookie
SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)

Group: General Forum Members
Points: 31 Visits: 66
BUT I dont want district 2,3,4 to show up in list box before I search. When I search it only shows district 1.
ProofOfLife
ProofOfLife
SSC Rookie
SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)

Group: General Forum Members
Points: 48 Visits: 9474
I'm sorry, I seem to have misunderstood your initial post so perhaps it would be best if you gave me some background to your enquiry.

Firstly, what is it that you are building and what is the purpose of this query?

Secondly, what sort of control is [Forms]![Austin Police Department- District 1]![txtSearch2]?

Cheers
sasansamani
sasansamani
SSC Rookie
SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)

Group: General Forum Members
Points: 31 Visits: 66
The list box is retrieving the data from the query. Right now the list box shows every district(1,2,3,4). I want the list box to show district 1 only. In other words, I want to be able to filter on district 1 when I search.

Look at my attachments.
Attachments
3.JPG (7 views, 161.00 KB)
grovelli-262555
grovelli-262555
SSC-Enthusiastic
SSC-Enthusiastic (116 reputation)SSC-Enthusiastic (116 reputation)SSC-Enthusiastic (116 reputation)SSC-Enthusiastic (116 reputation)SSC-Enthusiastic (116 reputation)SSC-Enthusiastic (116 reputation)SSC-Enthusiastic (116 reputation)SSC-Enthusiastic (116 reputation)

Group: General Forum Members
Points: 116 Visits: 872
Hi, what happens if you use
WHERE [Austin Police Department].District = 1 AND ((([Austin Police Department].Name) Like "*" & [Forms]![Austin Police Department- District 1]![txtSearch2] & "*")) OR ((([Austin Police Department].Location) Like "*" & [Forms]![Austin Police Department- District 1]![txtSearch2] & "*")) OR ((([Austin Police Department].[Phone Number]) Like "*" & [Forms]![Austin Police Department- District 1]![txtSearch2] & "*")) OR ((([Austin Police Department].[Position Title]) Like "*" & [Forms]![Austin Police Department- District 1]![txtSearch2] & "*"))
?
ProofOfLife
ProofOfLife
SSC Rookie
SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)SSC Rookie (48 reputation)

Group: General Forum Members
Points: 48 Visits: 9474
Hi

On the assumption that the query you have shown in your initial post is the rowsource for your list box, if you want only District 1 records to be displayed, you have to include this value (ie 1) in the District column for each Criteria row specified in the Query Designer. For instance, the Criteria row with the selection in the Name column should also have a 1 specified in the District column.

The SQL generated by this is probably going to look something like the WHERE I have already posted (I should have explained it as per this post right from the get go), or Access may modify it to look like the alternative suggested by grovelli. Faced with this problem I would probably manually alter the SQL as per grovelli's method.

All the best.
sasansamani
sasansamani
SSC Rookie
SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)

Group: General Forum Members
Points: 31 Visits: 66
I found the solution yesterday. thank you for your help. here is the query

SELECT [Austin Police Department].Name, [Austin Police Department].Location, [Austin Police Department].[Phone Number], [Austin Police Department].District, [Austin Police Department].[Position Title]
FROM [Austin Police Department]
WHERE ((([Austin Police Department].Name) Like "*" & [Forms]![Austin Police Department- District 1]![txtSearch2] & "*") AND (([Austin Police Department].District)="1")) OR ((([Austin Police Department].Location) Like "*" & [Forms]![Austin Police Department- District 1]![txtSearch2] & "*") AND (([Austin Police Department].District)="1")) OR ((([Austin Police Department].[Phone Number]) Like "*" & [Forms]![Austin Police Department- District 1]![txtSearch2] & "*") AND (([Austin Police Department].District)="1")) OR ((([Austin Police Department].District) Like "*" & [Forms]![Austin Police Department- District 1]![txtSearch2] & "*" And ([Austin Police Department].District)="1")) OR ((([Austin Police Department].District)="1") AND (([Austin Police Department].[Position Title]) Like "*" & [Forms]![Austin Police Department- District 1]![txtSearch2] & "*"));
grovelli-262555
grovelli-262555
SSC-Enthusiastic
SSC-Enthusiastic (116 reputation)SSC-Enthusiastic (116 reputation)SSC-Enthusiastic (116 reputation)SSC-Enthusiastic (116 reputation)SSC-Enthusiastic (116 reputation)SSC-Enthusiastic (116 reputation)SSC-Enthusiastic (116 reputation)SSC-Enthusiastic (116 reputation)

Group: General Forum Members
Points: 116 Visits: 872
I doubt it's going to work because you cannot set District to 1 and something else at the same time
OR ((([Austin Police Department].District) Like "*" & [Forms]![Austin Police Department- District 1]![txtSearch2] & "*" And ([Austin Police Department].District)="1"))
sasansamani
sasansamani
SSC Rookie
SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)

Group: General Forum Members
Points: 31 Visits: 66
well its working right now. there is no problems with the database.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search