Results 1 to 9 of 9
  1. #1
    BradWFresno is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2014
    Posts
    5

    Conditional text in query help. If text is blank return all.

    I have a form called "New Report" and I have 3 text boxes on it. There is a subform that pulls a query.



    One field is SDATE (formatted for date)
    One field is EDATE (Formatted for date)
    One field is IDNUM (formatted as text)

    In the query I want to filter by ID number if one is entered into the text box IDNUM. In the conditions field of the query for IDNUM I have the following.

    Code:
    IIf([Forms]![New Report]![IDNUM]=Null,Null,[Forms]![New Report]![IDNUM])
    It somewhat works if I put an ID number in the field however if I leave it blank it does not ever return any records. When left blank I would like it to return all records.

    Thank you,

    Brad

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Cannot test for =Null. Review http://allenbrowne.com/casu-12.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Try:
    IIf([Forms]![New Report]![IDNUM] Is Null,Null,[Forms]![New Report]![IDNUM])
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  4. #4
    BradWFresno is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2014
    Posts
    5
    I made some changes but still need help

    I have a form called "New Report" and I have 3 text boxes on it. There is a subform that pulls a query.

    One field is SDATE (formatted for date)
    One field is EDATE (Formatted for date)
    One field is IDNUM (formatted as text) default value abc

    In the query I want to filter by ID number if one is entered into the text box IDNUM. In the conditions field of the query for IDNUM I have the following.

    Code:
    IIf([Forms]![New Report]![IDNUM]= "abc","2618",[Forms]![New Report]![IDNUM])

    This will return all values relation to 2618 what do I need to change to get all values?

    Thank you,

    Brad

  5. #5
    BradWFresno is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2014
    Posts
    5
    Quote Originally Posted by Bob Fitz View Post
    Try:
    IIf([Forms]![New Report]![IDNUM] Is Null,Null,[Forms]![New Report]![IDNUM])
    this did not work.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    IDNUM is a text type field?

    Try

    LIKE [Forms]![New Report]![IDNUM] & "*"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    BradWFresno is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2014
    Posts
    5
    Quote Originally Posted by June7 View Post
    IDNUM is a text type field?

    Try

    LIKE [Forms]![New Report]![IDNUM] & "*"
    This returned everything even if I put a specific value. I would like to have a specific value or Like "*" if there is not a specific value entered into the text field.

    I tried
    IIf([Forms]![New Report]![IDNUM]="",Like "*",[Forms]![New Report]![IDNUM])

    but after I save it it turns into

    IIf([Forms]![New Report]![IDNUM]="",([dbo_EMPLOYEES].[IDNUM]) Like "*",[Forms]![New Report]![IDNUM])

    which does not work. So close...

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The LIKE operator and wildcard criteria should return only the records that match. This is a proven filter method for text type fields. Why would every record return? By 'into the text field' do you mean the IDNUM textbox on form?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    BradWFresno is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2014
    Posts
    5
    Quote Originally Posted by June7 View Post
    The LIKE operator and wildcard criteria should return only the records that match. This is a proven filter method for text type fields. Why would every record return? By 'into the text field' do you mean the IDNUM textbox on form?
    You are correct I was mistaken as I did not close my form before I tested it was caching.

    This did fix it Thank you!

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

Similar Threads

  1. Replies: 1
    Last Post: 05-17-2012, 02:41 PM
  2. Replies: 8
    Last Post: 05-16-2012, 09:30 AM
  3. Replies: 1
    Last Post: 04-26-2012, 08:31 PM
  4. Replies: 1
    Last Post: 11-05-2010, 04:31 PM
  5. Replies: 1
    Last Post: 05-17-2010, 12:21 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