Results 1 to 9 of 9
  1. #1
    Jimruns919 is offline Advanced Beginner
    Windows 10 Access 2019
    Join Date
    Jun 2023
    Location
    Pennsylvania
    Posts
    32

    How to create a query with multiple conditions

    Hi,



    This is my first post.

    Over the last 3 weeks or so I have taught myself MS Access and created a rather large database which is going to help the front desk employees with a specific task - Day Camp Registration.

    There are many different moving parts but the specific I am trying to fix is a query I created. I created a query for each of the 7 weeks of camp. When someone signs up they can sign up for any of three spots, Camp, Sports or crafts. So they do not necessarily have to sign up for camp for the day and only sign up for the sports or craft activities for later in the day. The issue is that the query lists everyone attending camp to make a roster for the counselors for each week and breaks it down by the 4 age groups.

    That works. The issue is if someone does not sign up for camp but only the sports or crafts activities they are not listed.

    I have all the fields in the query and the criteria is set for CAMP as <> 0.

    How do I adjust it so if either camp, sports or crafts are <> 0 then they will be listed on the query?

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Put the criteria on separate lines in the query designer, though it sounds like your db is not normalised.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I created a query for each of the 7 weeks of camp
    Not wise. One query that uses a parameter(s) is usually best.

    Actually, I think the db may very well be normalized since if the activity is in (eg.) tblActivities and the records are ActivityType (camp, sport, craft or their related numeric pk versions) then you will need each type on a separate line as advised. But if what you need are numbers by participant type, that would require either a Totals query or a report or a form/subform setup with calculated controls. Reports generally do a better job of presentation and are meant to be printed if that helps.

    EDIT - a pic of your table relationships, if you have created them, would probably help with getting focused answers. See "how to attach files" at the top of the page if needed, since you cannot copy/paste images here.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    Jimruns919 is offline Advanced Beginner
    Windows 10 Access 2019
    Join Date
    Jun 2023
    Location
    Pennsylvania
    Posts
    32
    Quote Originally Posted by Micron View Post
    Not wise. One query that uses a parameter(s) is usually best.

    Actually, I think the db may very well be normalized since if the activity is in (eg.) tblActivities and the records are ActivityType (camp, sport, craft or their related numeric pk versions) then you will need each type on a separate line as advised. But if what you need are numbers by participant type, that would require either a Totals query or a report or a form/subform setup with calculated controls. Reports generally do a better job of presentation and are meant to be printed if that helps.

    EDIT - a pic of your table relationships, if you have created them, would probably help with getting focused answers. See "how to attach files" at the top of the page if needed, since you cannot copy/paste images here.
    Click image for larger version. 

Name:	daycamp query.jpg 
Views:	27 
Size:	259.3 KB 
ID:	50404 This is the query. I have Week6Camp criteria <>0 but I also need week6craft and week6sports to show even if week6camp =0

  5. #5
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Hi
    To start with the Relationships between the 2 tables are wrong.

    A Camper would attend Camp 1 or more Weeks

    Your CamperInfo_tbl has a PK of CamperID

    The related table Week6Camper_tbl should have a FK named CamperID

    You would then Link CamperID in Both Tables and Enforce Referential Integrity.

    I also thing you have created a table for Each Week of Camp?

    This again is wrong. You should have 1 table to record all of the Weeks.

    Can you upload a copy of the database without any Confidential data?
    Last edited by mike60smart; 06-21-2023 at 01:08 PM. Reason: Add more
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I agree - needs some fixing. Suggest that as you go, you stop using spaces in object names. Also CamperAge field is a no-no, especially if it is a calculated field. You would perform that calculation as required. Think of a table as being an entity and the fields are attributes of the entity. If you were a camper, do you have a feature (attribute that describes you) named TodaysDate? There are several others like that as well. I suggest you forget about uploading anything just yet, and instead, research db normalization but you are free to do otherwise of course. Then take another crack at your tables and repost the relationships for consideration. I'm seeing 6 tables or more - depends on what your intent is with some of them (e.g. BirthCert, shirt stuff, which also probably shouldn't be where you have them). As for Camper Sex, a table like tlbGender would be better than a field, and IMO, Sex is rarely included in a field named by accomplished designers.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    Join Date
    Apr 2017
    Posts
    1,681
    When you design a database, then design it and it's components to be usable for any time period, not for specific year, month, or week
    So looking at your relations picture, you probably need:
    tblCampYears: CampYear, [CampLocation], [FirstWeek], [LastWeek], ...;
    tblCampYearWeeks: CampYear, CampWeek;
    tblCampActivities: CampActivityID; ActivityDescription (ActivityDescriptions will be like "camping", "sport", "crafting", etc.);
    tblCampers: CamperID, FirstName, LastName, Gender, DOB;
    tblYearCampers: YearCamperID, CampYear, CamperID, RegDate, ...;
    tblYearCampWeekActivities: YearCampWeekActivityID, CampYear, CampWeek, CampAcctivityID, ...;
    tblYearCampWeekActivityCosts: YearCampWeekActivityCostID: YearCampWeekActivityID, ActivityCost (this design allows activities of same type on different weeks have different costs);
    tblYearCamperActivities:YearCamperActivityID, YearCampWeekActivityID, YearCamperID;
    etc.

    I think you got the idea!

  8. #8
    Jimruns919 is offline Advanced Beginner
    Windows 10 Access 2019
    Join Date
    Jun 2023
    Location
    Pennsylvania
    Posts
    32
    Thank you for your input. i know I still have a lot to learn and I make fields without spaces but I guess I missed on some.

    however, I did get this to work and I figured out my error. Basically I did the OR criteria wrong. Once I added the weekxcraft <>0 and weekxsports <>0 it worked perfectly.

  9. #9
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    You still need to think about your table structures.

    If you do not fix these now then you will regret it later down the line.
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

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

Similar Threads

  1. Replies: 3
    Last Post: 08-08-2021, 10:23 AM
  2. Replies: 8
    Last Post: 09-08-2017, 01:23 PM
  3. Replies: 14
    Last Post: 05-22-2013, 03:33 PM
  4. Replies: 6
    Last Post: 02-13-2011, 06:02 PM
  5. Update Query - Multiple SETS and WHERE conditions
    By jasonbarnes in forum Queries
    Replies: 26
    Last Post: 12-15-2010, 01:08 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