|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Friday, January 11, 2013 11:52 AM
Points: 28,
Visits: 50
|
|
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;
 |  |  |  |
2.JPG
(7 views, 116.58 KB) |
|
|
|  |  |  |  |
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Thursday, February 21, 2013 9:11 PM
Points: 45,
Visits: 9,440
|
|
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
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Friday, January 11, 2013 11:52 AM
Points: 28,
Visits: 50
|
|
| 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.
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Thursday, February 21, 2013 9:11 PM
Points: 45,
Visits: 9,440
|
|
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
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Friday, January 11, 2013 11:52 AM
Points: 28,
Visits: 50
|
|
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.
 |  |  |  |
3.JPG
(7 views, 161.31 KB) |
|
|
|  |  |  |  |
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Yesterday @ 1:22 PM
Points: 81,
Visits: 680
|
|
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] & "*")) ?
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Thursday, February 21, 2013 9:11 PM
Points: 45,
Visits: 9,440
|
|
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.
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Friday, January 11, 2013 11:52 AM
Points: 28,
Visits: 50
|
|
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] & "*"));
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Yesterday @ 1:22 PM
Points: 81,
Visits: 680
|
|
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"))
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Friday, January 11, 2013 11:52 AM
Points: 28,
Visits: 50
|
|
| well its working right now. there is no problems with the database.
|
|
|
|