Results 1 to 6 of 6
  1. #1
    CandaceB is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Location
    Maryland
    Posts
    3

    Need help making ranges

    I guess I should start by saying I'm a beginner in Access. I have enough knowledge to be a menace. Not a threat or a danger, just enough to stir up trouble.



    I have a membership database. In this I want to group the children by their ages and gender. Ages can range from 1 month to 17+ years. I used this statement

    IIf(DateDiff("m",[BDay],Date())<12,DateDiff("m",[BDay],Date()),DateDiff("yyyy",[BDay],Date())+Int(Format(Date(),"mmdd")<Format([BDay],"mmdd"))) to get the age. field name:[Age]

    In a separate text box I used this statement IIf(DateDiff("m",[BDay],Date())<12,"mth"," yr") to indicate whether the age was in months or years. field name:[Mth Yr] So far (I think) this will work for me.

    What I would like to do is create the following age ranges to group the kids:

    1-12 months, group 1
    2-4 years, group 2
    5-7 years, group 3
    8-10 years, group 4
    11-13 years, group 5
    14-17 years, group 6
    18+ years, group 7.

    I have a column in my query that calculates the age. I also have a column for the month year text. I made separate columns in the query for the groups, but I don't think this will work when I want to group them on the report. I could do an iif statement, but I need to have a 2 part expression. Like if [Age] is <12 and [Mth Yr] = "mth" then put a 1. Every number below 12 could be the age in months or years. I don't want to group 3 month old kids with 3 year old kids.

    Please help.I've been playing with this for 2 days.
    Candace

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    For 1-12 months, year will be 1. Year 1 would be group 1.

    IIf(DateDiff("m",[BDay],Date())<12, 1, calc for older ages)
    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
    CandaceB is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Location
    Maryland
    Posts
    3
    Thank you for your response. Does the "calc for older ages" mean to use the datediff function to calculate the other ages in years? How will I get the other group ranges? Group 2 includes kids ages 2-4 years. If this is the formula I would use, where would I use it? I tried to put it in the column on the query by typing: New:IIf(DateDiff("m",[BDay],Date())<12, 1, calc for older ages). I got a caution box stating that the expression contains invalid syntax. When I click OK, the for is highlighted. I'm missing something.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    'calc for older ages' means 'put your formula here'.

    I was just being too lazy to copy/paste what you show in your original post.

    Then use the Age field to calculate groups.

    Switch([Age]=1,1, [Age]<5,2, [Age]<8,3, [Age]<11,4, [Age]<14,5, [Age]<18,6, [Age]>17,7)
    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
    CandaceB is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Location
    Maryland
    Posts
    3
    Thank you thank you! Never seen the switch function in my searches. Now I have a little more knowledge to add to my menacing. Your my new hero June7. You ARE a Super Moderator.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Choose() is another versatile function you might get familiar with.
    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.

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

Similar Threads

  1. How to Program Two Date Ranges?
    By Jaynen in forum Database Design
    Replies: 5
    Last Post: 02-22-2013, 06:58 AM
  2. Searching for Date Ranges
    By phd42122 in forum Access
    Replies: 2
    Last Post: 05-07-2012, 07:20 AM
  3. two different time ranges
    By dylan_dog in forum Queries
    Replies: 1
    Last Post: 01-13-2012, 11:54 PM
  4. Working with date ranges
    By Acegundam in forum Queries
    Replies: 3
    Last Post: 11-04-2011, 02:04 PM
  5. Count records by ranges
    By mjhopler in forum Access
    Replies: 2
    Last Post: 07-09-2011, 12:11 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