Results 1 to 7 of 7
  1. #1
    Xterra14s is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    May 2016
    Posts
    32

    SQL Statement help

    Current SQL Statement:


    SELECT IssuesDB.ID, IssuesDB.User, IssuesDB.Date, IssuesDB.Status, IssuesDB.Resolution
    FROM IssuesDB
    WHERE (((IssuesDB.ID) Like "*" & [forms]![EndUser Search]![Ticket#] & "*") AND ((IssuesDB.User) Like "*" & [forms]![EndUser Search]![User] & "*")) OR (((IssuesDB.ID) Like "*" & [forms]![EndUser Search]![User] & "*") AND ((IssuesDB.User) Like "*" & [forms]![EndUser Search]![Ticket#] & "*"));

    Goal: I created a search form in a ticket system database. I have two ways of searching for a ticket: First is by the ticket number but if the user doesn't have that number they can also search by their Username. If I enter the Ticket number using the current SQL statement it works beautifully. If I enter the username it's returning all users since name all share letters example. If in the drop down menu I select the name Bob Green. I'll get results for Bob Green, Tom Bean, Rob Tree since they all share the letter O, E, and so on. I want the names to only be an exact match.

    I tried this SQL Statement also but with this it requires the Ticket number AND Username to be an identical match. I want one or the other, not both.

    SELECT IssuesDB.ID, IssuesDB.User, IssuesDB.Date, IssuesDB.Status, IssuesDB.ResolutionFROM IssuesDB
    WHERE (((IssuesDB.ID)=[Forms]![EndUser Search]![Ticket#]) AND ((IssuesDB.User)=[Forms]![EndUser Search]![User]));


    Any and all help would be greatly appreciated!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    change AND to OR

  3. #3
    Xterra14s is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    May 2016
    Posts
    32
    Quote Originally Posted by ranman256 View Post
    change AND to OR
    I did this but it wont show anything in the Query when I look up by User. If I search by Ticket# it does give me results. I think it has to do with ticket# being blank, is there a way to include a null ticket#?

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,836
    try

    WHERE (((IssuesDB.ID)=[Forms]![EndUser Search]![Ticket#] OR [Forms]![EndUser Search]![Ticket#] is null) AND ((IssuesDB.User)=[Forms]![EndUser Search]![User] OR [Forms]![EndUser Search]![User] is null));

    Using #, spaces or other non alphanumeric characters in table and field names is a bad idea. At some point it will come back to bite you with an error message that does not make sense and you will spend hours trying to figure it out

  5. #5
    Xterra14s is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    May 2016
    Posts
    32
    Quote Originally Posted by Ajax View Post
    try

    WHERE (((IssuesDB.ID)=[Forms]![EndUser Search]![Ticket#] OR [Forms]![EndUser Search]![Ticket#] is null) AND ((IssuesDB.User)=[Forms]![EndUser Search]![User] OR [Forms]![EndUser Search]![User] is null));

    Using #, spaces or other non alphanumeric characters in table and field names is a bad idea. At some point it will come back to bite you with an error message that does not make sense and you will spend hours trying to figure it out
    It didn't bring back any results =(

  6. #6
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,836
    well that is the usual way of handling null controls for a multiple criteria.

    suggest confirm your form is populated with data which will return something.

    Also try changing the AND to OR per Ranmans post

  7. #7
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,698
    How about 2 SQL selects, one for when the name is provided and the other when the ticket number is provided. Then the search is on the name or the ticket, not having to provide for nulls at all.

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

Similar Threads

  1. Using the IIF statement?
    By Terryb07 in forum Forms
    Replies: 2
    Last Post: 06-07-2015, 07:00 PM
  2. VBA If Statement
    By BatmanMR287 in forum Access
    Replies: 4
    Last Post: 05-19-2015, 03:13 AM
  3. Replies: 11
    Last Post: 04-29-2015, 01:38 PM
  4. if statement in sql statement, query builder
    By 54.69.6d.20 in forum Access
    Replies: 4
    Last Post: 09-11-2012, 07:38 AM
  5. Replies: 7
    Last Post: 08-17-2011, 01:49 PM

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