Share via

Query Based on form checkbox

Anonymous
2013-02-04T21:16:57+00:00

I have no experience using a form to do a query in Access but that has been my assigned task. 

We have a database with many columns of data.  I have a form that gives people the option to filter the data based on values in each of those fields.  For example, you can choose the data that corresponds to a "class" of 1 or 2, you can choose the records corresponding to a "zone" of 1, 2 or 3.  Any number of things can be combined to produce the desired dataset.

My problem is I have not figured out how to modify the code in the qry (not the form) so that a limitation does not have to be included.  My code so far for "class" is [forms]![block model]![class] but if someone does not want to limit the data search by a value within the "class" field I have not found a way to tell this code to exclude it.

On my form I included a check box that a person can check if they want to limit the search using that field.  Is there a way to have that code look at whether or not that checkbox has a check in it and if it does to run that code in the query?  If the checkbox is not checked that code would not be run and no limits would be placed on that field.  I hope this makes sense.

This query will not update anything in the data itself and the form is connected to a database of our data.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

11 answers

Sort by: Most helpful
  1. Anonymous
    2013-02-04T21:33:50+00:00

    Funny I searched several hours and found nothing ... until I posted this question.

    Like IIf([forms]![block model]![check_class]=-1,[forms]![block model]![class],"*")

    I answered my own question.  But the one I am looking for values greater than or equal to the value chosen in the list box is not working.  I still have to figure that one out.

    Was this answer helpful?

    2 people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2013-02-04T21:58:29+00:00

    "Fields are expensive, records are cheap". I fear you are "committing spreadsheet" by having many fields (columns) for your data. This is fine for Excel, but bad design for Access; I suspect you would do better to have THREE tables modeling the many-to-many relationship you now have embedded in each record.

    That said, a criterion

    ([Fieldname] >= [Forms]![YourFormName]![Controlname] OR [Forms]![YourFormName]![Controlname] IS NULL)

    will let you use form controls to specify criteria, but ignore that form control if it is blank.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  3. Anonymous
    2015-09-24T15:50:47+00:00

    now I am needing this same thing, Matt_Roger, can you elaborate more on what you did to make it work?

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2013-02-04T22:22:07+00:00

    I got it to work with the like iif but thanks for your help.

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2013-02-04T22:10:59+00:00

    Strange - not working.  I end up with a table with a record with a .2 record at the top (if searching for >=.2) and every other record has 0 in that field.

    I understand your concern.  I was working with the data set in Excel and perhaps thinking that their constant need to get me to update these tables based on their criteria would mean they would have to renew my contract in July, they asked if I could create a form in Access where anyone would be able to pick their desired criteria and spit out data from the database.  So obviously I was not going out of my way to break up our database into access friendly tables.  I am very familiar with the format of Access but this is what was asked of me and this is what I will give them.  Perhaps it can be done in Excel as well but the boss suggested Access.

    Was this answer helpful?

    0 comments No comments