Results 1 to 3 of 3
  1. #1
    MarkF2004 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2014
    Posts
    6

    Grouping Data Into Sections from A Field?

    Hi there



    [Caveat: I am new-ish to Access 2010, I have zero VBA knowledge but I am willing to try stuff out if I can get help! I am tasked with sorting out a database and progress (so far) is fairly good. I would appreciate any help or pointers that you might provide.]

    I have a database with a list of clients. One field is for their date of birth.

    I have to report on equality and need to advise how many clients we have within the following age groups:

    16 - 24
    25 - 34
    35 - 44
    45 - 54
    55 - 64
    65+

    I have looked through the group and sort functions and cannot see anything obvious to help me there. Can anyone get me started at all?

    Thank you.

    MarkF

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    You need to change the query, make a virutal field with a home grown function.
    In vbe, INSERT, MODULE,
    then paste this code.
    Save

    In the query, in a new column, AgeGrp([age]) (if you have a field called age, or calculate age in it: datediff("y",date1,date())

    Code:
    Public Function AgeGrp(byval pvAge)
       If pvAge >= 16 And pvAge <= 24 Then
           AgeGrp = "16 - 24"
       ElseIf pvAge >= 25 And pvAge <= 34 Then
           AgeGrp = "25 - 34"
       ElseIf pvAge >= 35 And pvAge <= 44 Then
           AgeGrp = "25 - 34"
       ElseIf pvAge >= 45 And pvAge <= 54 Then
           AgeGrp = "25 - 34"
       ElseIf pvAge >= 55 And pvAge <= 64 Then
          AgeGrp = "25 - 34"
       ElseIf pvAge > 64 Then AgeGrp = "65+"
    End Function

  3. #3
    MarkF2004 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2014
    Posts
    6
    Hello there ranman256

    Thank you for that. I will get to work on it and report progress...

    Regards

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

Similar Threads

  1. Replies: 4
    Last Post: 06-07-2014, 01:54 PM
  2. Replies: 3
    Last Post: 05-06-2014, 10:17 AM
  3. Replies: 2
    Last Post: 06-02-2013, 08:07 PM
  4. Replies: 1
    Last Post: 04-16-2013, 09:51 PM
  5. Replies: 10
    Last Post: 08-21-2012, 07:16 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