Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    urosm993 is offline Novice
    Windows 10 Access 2013
    Join Date
    Nov 2015
    Posts
    11

    Angry Search Query - Empty fields problem

    I have a search form with many fields including date range, name, some number ranges etc.
    Have one button to run a search query so it can select from table searched data.
    But the problem I'm facing is how to INCLUDE all the records when I don't specify a number range in the field.
    I tried isNull function, and isEmpty but for some reason it's not working...

    Is there an efficient way to solve this. If I leave the field blank, to just don't effect the search in any way?


    Thank you
    Attached Thumbnails Attached Thumbnails Captu22re.PNG  

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Do you mean if the control on form is left empty? You will have to provide the query with alternate value if user does not enter any. Is this a date parameter? Like:

    BETWEEN Nz([Foms]![Search]![EFod], #1/1/1900#) AND Nz([Foms]![Search]![EFdo], #12/31/2900#)

    If it is not a date but a number, then use some extreme numbers that will insure capture of records. And don't use the # delimiters.


    I NEVER use dynamic parameterized queries. I prefer VBA: http://www.allenbrowne.com/ser-62.html

    Re use of Nz() in query http://allenbrowne.com/QueryPerfIssue.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
    urosm993 is offline Novice
    Windows 10 Access 2013
    Join Date
    Nov 2015
    Posts
    11
    Thank you, it was helpful I have another thing to ask.
    I have some check box fields in my table. For example is some person a smoker on not (yes/no), and I want to search it through my form with radio buttons like the picture i attached shows.
    Can someone help mi with that, I see there are integer values attached to each radio buttons, but how could I write that in query...Click image for larger version. 

Name:	Capture.PNG 
Views:	15 
Size:	2.3 KB 
ID:	23049

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    This is why I avoid Yes/No fields and never use dynamic parameterized queries. I really don't know any way to structure conditional parameter for Yes/No field to allow the All option.
    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.

  5. #5
    urosm993 is offline Novice
    Windows 10 Access 2013
    Join Date
    Nov 2015
    Posts
    11
    Well, as I'm trying to make extremely user-friendly database, I'm not really sure if just text field instead of check box is acceptable. There should be a way to show checked and unchecked when radio button "all" is selected. When I chose yes to select records with only checked, and when NO is chosen to select only record with unchecked boxes

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Maybe calculate another field and apply conditional to that constructed field.

    SmokerYN: IIf([Smoker], "T", "F")

    LIKE Switch([Foms]![Search]![option group]=1, "T", [Foms]![Search]![option group]=2, "F", [Foms]![Search]![option group]=3, "*")

    Otherwise, I would use VBA.
    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
    urosm993 is offline Novice
    Windows 10 Access 2013
    Join Date
    Nov 2015
    Posts
    11
    As I saw that there are numbers joined to these radio buttons, and I think that checkBox fields act in the way they have values 0 and -1. Not sure where I saw that, but i think 0 is unchecked and -1 is checked. And I could give -1 to Yes radio button and 0 to No radio button, and try to write a simple criteria Select whatever.. where [checkBoxField] =[Forms]![Search]![Radio1].. But I'm not really sure on syntax and If it's possible to solve it that way.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    No, that will not deal with the All selection. I think I have offered only viable approach for dynamic parameterized query.
    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
    urosm993 is offline Novice
    Windows 10 Access 2013
    Join Date
    Nov 2015
    Posts
    11
    Well, I still have a button and I can run a query. You are saying that I cannot search for a checkBox value in the same way I do for text field values?

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Not if you want the 'All' option. They hold numeric data - wildcards are only useful with text data and the logical operators (=, <, >) won't help. Operators cannot be dynamic. That's why I suggest criteria on a calculated text value.

    Let me double check on the wildcard.

    Okay, I have learned something new. Wildcard works with yes/no field.

    LIKE Switch([Foms]![Search]![option group]=1, "-1", [Foms]![Search]![option group]=2, "0", [Foms]![Search]![option group]=3, "*")

    Set the Option Group with 3 as DefaultValue.
    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.

  11. #11
    urosm993 is offline Novice
    Windows 10 Access 2013
    Join Date
    Nov 2015
    Posts
    11
    Somehow it's not working. How could I search just records that are checked? Field IsSmoker Table People Criteria =-1 or true? I'm not sure how I can handle that in query design. Can I write that switch there? Under criteria I have to specify 'fields of what values will appear in the query'. Maybe =-1 AND [Forms]![Search]![option group]=1 OR =0 AND [Foms]![Search]![option group]=2 ....

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    What does not working mean, what happens - error message, wrong results, nothing?

    The suggested criteria worked in my db. What exactly did you do? Post the query SQL statement.
    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.

  13. #13
    urosm993 is offline Novice
    Windows 10 Access 2013
    Join Date
    Nov 2015
    Posts
    11
    Sorry I reply so late, I wasn't able to reply earlier. This is what I have done so far. This is a mess. It's not just what I wrote, access is adding something on it's own. I gave up on trying to add a code to SQL part, and trying to add to design. On these pictures is working search for all the fields, To show everything in search if either of them is empty.
    Now it's not easy to add the option button search to all of that... Here are some parts to show you where I got confused adding what you have suggested



    Click image for larger version. 

Name:	FORM1.PNG 
Views:	8 
Size:	18.5 KB 
ID:	23147Click image for larger version. 

Name:	Design.PNG 
Views:	8 
Size:	26.6 KB 
ID:	23149Click image for larger version. 

Name:	Querry.PNG 
Views:	8 
Size:	109.9 KB 
ID:	23150


    It's asking a value that should read from the OptionGroup. And If I enter 0 it shows all (as it should). All other numbers doesn't work (Shows nothing for 1 and 2)
    Click image for larger version. 

Name:	VALUE..PNG 
Views:	9 
Size:	6.6 KB 
ID:	23151Click image for larger version. 

Name:	OptPusac.PNG 
Views:	9 
Size:	3.3 KB 
ID:	23152

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    That popup normally means Access can't find the referenced object, usual cause is misspelling.

    I did not suggest constructing the two right hand fields. Why do you have those?

    The Switch expression goes in Criteria row below the Yes/No field. Just like any of the other parameters you already have.

    However, as already noted, I would not use parameterized query. This query is getting too complex.
    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.

  15. #15
    urosm993 is offline Novice
    Windows 10 Access 2013
    Join Date
    Nov 2015
    Posts
    11
    Not sure about what right hand fields you are thinking about. With nulls?
    Yes, it's asking for the value, and the funny part is, when I enter the value it still doesn't work. I got empty table, except for value 0, then I get all the records as I should

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Totals Query and Empty Fields
    By AccessNub in forum Queries
    Replies: 4
    Last Post: 09-20-2013, 01:27 PM
  2. Query Three Fields One can be Empty
    By bgold01 in forum Queries
    Replies: 2
    Last Post: 04-16-2013, 10:50 AM
  3. Replies: 2
    Last Post: 04-23-2012, 10:13 PM
  4. Replies: 4
    Last Post: 11-20-2011, 01:08 PM
  5. Update Query on empty fields
    By bryan in forum Access
    Replies: 3
    Last Post: 01-18-2011, 11:36 AM

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