Results 1 to 7 of 7
  1. #1
    DBaker7777 is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2012
    Posts
    14

    Query Criteria

    I have a form that allows the user to select a date range and then a couple of textboxes that allow for criteria. The below works if you enter data into only one of the textboxes 45 or 47, but when you have criteria in both it produces no results. Am I missing something?



    Code:
    SELECT History.MACCODE, History.Department, History.IndividualName, History.Address, History.Address2, History.Address3, History.City, History.State, History.Zip, History.LabelType, History.PrintDate
    FROM History
    WHERE ((History.MACCODE Like [Forms]![frmtele]![Text45] & "*" & "*" & "*" & "-" & "*" & "*" & "*")
              Or ([Forms]![frmtele]![Text45] IS Null))
              AND((History.MACCODE Like [Forms]![frmtele]![Text47] & "*" & "*" & "*" & "-" & "*" & "*" & "*")
              Or ([Forms]![frmtele]![Text47] IS Null))

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,389
    Maybe History.MACCode cannot be like Text45 and Text47 at the same time.
    Try entering same data into Text45 and Text47 and see what happens.

    BTW, "*" & "*" & "*" & "-" & "*" & "*" & "*" is same as "***-***"

  3. #3
    DBaker7777 is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2012
    Posts
    14
    Quote Originally Posted by davegri View Post
    Maybe History.MACCode cannot be like Text45 and Text47 at the same time.
    Try entering same data into Text45 and Text47 and see what happens.

    BTW, "*" & "*" & "*" & "-" & "*" & "*" & "*" is same as "***-***"

    It did work when I entered the same data in Text45 and Text47. Is there something I can add so it will include what is in Text45 and Text47 at the same time? If I enter 2 in Text45 and 9 in Text47 it should pull all the data for those two numbers.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Your test would require the value to have both 2 and 9 in it. Do you perhaps want OR instead of AND?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    DBaker7777 is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2012
    Posts
    14
    That worked, but now when one of the textboxes is null it includes everything. For instance when I just enter 2 in Text45 and nothing in Text47 it displays 0,2,9 results.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Your Is Null test is doing that. That basically says to give you everything if the textbox is left empty.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    DBaker7777 is offline Novice
    Windows XP Access 2007
    Join Date
    Jul 2012
    Posts
    14
    What could I enter so that if Text45 and Text47 are both populated it will give me the criteria of both, but if Text45 is populated and Text47 is left blank that it only gives me what is in Text45 or vice versa?

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

Similar Threads

  1. Replies: 2
    Last Post: 04-02-2015, 12:45 PM
  2. Replies: 1
    Last Post: 11-13-2014, 11:34 PM
  3. Replies: 4
    Last Post: 08-30-2014, 10:23 AM
  4. Replies: 5
    Last Post: 09-20-2012, 03:27 PM
  5. Replies: 5
    Last Post: 08-02-2012, 09:44 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