Results 1 to 3 of 3
  1. #1
    jfg863 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jun 2014
    Posts
    7

    Access Form Allowing for Blank Fields and Query Question

    I have a question to do with having 4 criteria (4 separate textboxes in a form) that I would like to tie to my query. If I add the 4 fields into the criteria area in the query (such as [Forms]![ValidationForm1_3]![Field]) and I place information in each of the 4 fields in the form, the results comes back as expected.



    But what if I only want to query for one of the 4 fields and I leave the other 3 fields blank on the form but keep them in the criteria in the query, then no results will come back.

    Is there a way I can allow some of the fields to be blank while also having the option to put all of the data in for each field if I want (meaning, without having to take out parts of the query every time, but instead allowing me to click my macro on my form, regardless of blank fields or not, and it coming back with what I wanted.

    For example, say I have 4 fields (field1, field2, field3, field4) on my form as textboxes where you can enter information to query the database.
    I then put "Cat" in field1, nothing in field2, "55" in field3, and nothing in field4. The query would then come back with all the records that have Cat for field1 and 55 for field3 (these are just made up examples).

    What happens now though is if I leave one field blank on the form it comes back with no results. I have tried a few iif statements like for example:
    =IIf(IsNull([Forms]![Form1]![Field2])=True,"",[Forms]![Form1]![Field2]) is one of them for example which I put in the criteria area.

    Hopefully This explains it enough that someone understands what I'm trying to do? I appreciate any help, hopefully someone has done this before.

  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,963
    A method for text (and I think date/time) fields is to use LIKE operator and wildcard. Number field requires different approach.

    LIKE [Forms]![ValidationForm1_3]![Field] & "*"

    Is it possible that some records will not have data in these fields? If you still want those records, need to handle the Nulls.

    LIKE [Forms]![ValidationForm1_3]![Field] & "*" OR Is Null
    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
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,743
    You probably have an AND condition between each of the criteria. You could try changing to OR and see if that gives you what you want.
    You may get some ideas from this free video.

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

Similar Threads

  1. How to see if all fields of the form are blank.
    By behnam in forum Programming
    Replies: 5
    Last Post: 06-07-2014, 10:21 AM
  2. Query is excluding records with blank fields
    By Menelaus in forum Queries
    Replies: 1
    Last Post: 03-28-2013, 08:14 PM
  3. Replies: 5
    Last Post: 06-11-2012, 08:47 AM
  4. Blank Fields (Newbie Question)
    By xsbucks in forum Access
    Replies: 1
    Last Post: 12-17-2011, 08:11 PM
  5. searching for blank fields with a query
    By ironman in forum Queries
    Replies: 0
    Last Post: 03-04-2011, 03:48 PM

Tags for this Thread

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