Results 1 to 10 of 10
  1. #1
    dgaletar is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Location
    Washington, DC
    Posts
    85

    Question How to Use Criteria in a Query

    Hello. I am trying something new, and (of course) I am stuck!

    Here is (among a LOT of other things) what I have:




    • A "Vehicles" table that contains (among a LOT of other things) the following:

    PK? Field Name Data Type Row Source
    PK CustomerID Number
    Department Number SELECT [Department].ID, [Department].Department FROM Department ORDER BY [Department];
    AlternateID Short Text


    • A "Service" table that contains the following:

    PK? Field Name Data Type Row Source
    PK ServiceID AutoNumber
    CustomerID Number
    Date Date/Time


    • A "qryMaxPublicSafetyDates" query that looks like this:

    Click image for larger version. 

Name:	qryMaxDates.png 
Views:	11 
Size:	158.3 KB 
ID:	16475

    The problem is that when I run this query, I get zero results! If I instead remove the "Like Public Safety" criteria option, it runs fine, except with all of the results.

    My goal here is to run a query that returns ONLY the results from the "Public Safety" Department, and a second that returns ONLY the results from everyone EXCEPT the "Public Safety" Department.

    If you help me to figure out the first one, I know that I can easily accomplish the second.

    I'm not sure, but I think that it has something to do with where the criteria "Department" comes from. I mean, the fact that it is a "look up" field in the "Vehicles" table, could be the issue. So I created a named "Vehicles by Dept" that sorts all of the departments out along with the vehicles that belong to them, but that didn't work either.

    Any and ALL suggestions would be GREATLY appreciated!

    Thx,

    DG

  2. #2
    haissk is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    8
    Instead of Like Public Safety, if you put "= Public Safety" does it work, if it works then the problem is with like creteria.
    Try Like "*Public Safety*"

  3. #3
    dgaletar is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Location
    Washington, DC
    Posts
    85
    "= Public Safety" produces an error - "Data Type Mismatch in Criteria Expression".

    Like "*Public Safety*" returns no results.

  4. #4
    haissk is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    8
    Sorry i see that Department is a numeric field, or i am not able to get your exact tables, is there any way you post the Access file

  5. #5
    dgaletar is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Location
    Washington, DC
    Posts
    85
    No, your right. I think that it is a numeric field. It's like a "lookup" field I think. Sorry, but the file is protected and large, so I won't be able to do that. Any ideas???

  6. #6
    haissk is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    8
    You cannot apply like creteria on a Numeric field. Are you sure the Department field has the text values in it?

  7. #7
    dgaletar is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Location
    Washington, DC
    Posts
    85
    No, I'm sure that it DOESN'T have the text values in it! It has a numeric field. Do I need to change it???

  8. #8
    dgaletar is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2013
    Location
    Washington, DC
    Posts
    85
    I just went in and changed the field type from a "Numeric" field to a "Short Text" field. I then tried the query again and nothing... same end results. :-(

  9. #9
    haissk is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    8
    Sorry cant help until you give the exact table structure and values

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I did not read the whole thread but if Department is a Lookup Field in a table you need to determine the index for the specific department name you are after.

    Look in the table properties for the department field. Look at the value list and determine the index you need.

    So your criteria may be
    =1
    Or
    =4
    Or
    =0

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 05-02-2013, 11:07 AM
  2. Replies: 5
    Last Post: 05-01-2013, 11:39 AM
  3. Replies: 5
    Last Post: 09-20-2012, 03:27 PM
  4. Replies: 5
    Last Post: 08-02-2012, 09:44 AM
  5. Replies: 1
    Last Post: 07-13-2011, 11:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums