Results 1 to 2 of 2
  1. #1
    kwelch is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2009
    Location
    Chicago, IL, USA
    Posts
    20

    Query or macro for searching multiple yes/no fields

    I have a table with 4 disease conditions. Each disease is a separate field and is set to a yes/no data type.



    Click image for larger version. 

Name:	yesno1.jpg 
Views:	9 
Size:	101.5 KB 
ID:	26284

    I used a query and an IIF statement to convert the checkboxes to 1 or null as below.

    Click image for larger version. 

Name:	yesno2.jpg 
Views:	8 
Size:	96.1 KB 
ID:	26285

    I want a user (me, really) to be able to choose among the 4 diseases to find the particular patient. So, I might want to see who has allergies AND Asthma in one query, but in the next query find out who has bronchiectasis alone. Alternately, the next query might be who has all four conditions. So, I came up with the following Fields and Criteria:
    Field - Allergies: IIf([options]![Allergies]=Yes,1,0)
    Criteria - [Allergies: Enter 1 for Yes, 0 for No]

    Using this Query method, I can get the answers I want - IF I'm not looking just for a single condition. For example, If I make Allergies a "1" and do not enter anything for the other three diseases (neither a 1 or a 0), I get an empty query. If I enter allergies=1 and the other three diseases as 0, i get only the patients with allergies who do NOT have the other three diseases.

    For example, allergies=1, asthma=1, bronchiectasis=1, eosinophilia=0. The resulting query is accurate.
    Click image for larger version. 

Name:	yesno4.jpg 
Views:	8 
Size:	110.4 KB 
ID:	26287

    But, that's not what I always want. I may just want to see who has one disease. So, this query method is inadequate for me for two reasons: 1) it takes multiple steps; I'd like a button or something to do the work for me; 2) I cannot query a disease by itself to see how many instances of a single disease there are regardless of whether the other diseases coexist.

    I tried working with a split form and creating a macro.
    Click image for larger version. 

Name:	yesno3.jpg 
Views:	9 
Size:	117.4 KB 
ID:	26286

    Macro for command button: ApplyFilter, Where Condition = [Allergies] Like "*" & [Forms]![options][CheckAllergies] & "*" ...... etc. This only accepts 255 characters, so it worked for two of the check boxes in the Where Condition. However, when I deselected the 4 disease conditions on the form, the datasheet doesn't "reset" and list all the names again.

    So, I'd be interested in hearing what you experts suggest in terms of directions or tweaks.

    Thanks!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    You really shouldn't do it that way. Queries won't search across columns, they search vertically.
    A sub table to hold infinite ailments.TAilments.
    ID, ailment,date
    3,bronchitis,1/1/15
    3,pneumonia,2/2/16

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

Similar Threads

  1. Searching multiple fields in a table
    By KyleMac in forum Programming
    Replies: 2
    Last Post: 12-11-2014, 02:20 PM
  2. Replies: 36
    Last Post: 12-09-2013, 02:20 PM
  3. Searching Using a Query in Multiple Fields
    By RossIV in forum Queries
    Replies: 10
    Last Post: 07-24-2013, 06:32 AM
  4. searching for blank fields with a query
    By ironman in forum Queries
    Replies: 0
    Last Post: 03-04-2011, 03:48 PM
  5. Replies: 3
    Last Post: 02-08-2011, 10:25 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