Results 1 to 5 of 5
  1. #1
    Yeti is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    5

    Defined ranges in a calculated field

    Hi guys - you were very helpful last time, so I'm back for more



    I'm trying to create a calculated field in a query that will allow me to group numbers into irregular categories.

    My field is called "Experience" and it contains the number of years of experience an employee had in the field before being hired by this particular company. I'd like a new field that contains the text values "0-3," "4-9," "10-19," and "20+"

    I know how to set up the query to show me the number of employees per group, but I don't know how, in design view, to define my calculated field.

    Thanks!

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Have you considered creating a User Defined Function (UDF) in a standard module for this task?

  3. #3
    Yeti is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    5
    I haven't, and I'm not familiar with those. I can read up on them if you think they'd be a better option in this case. Where would I use this function?

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Your query would have a field similar to: YourFieldName: = ReturnGroup([Experience])

  5. #5
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    As an alternative to writing code, you could also create a "Ratings" table, put your experience criterias in one column there, then just simply write in a query:
    Code:
    SELECT [category], 
    
    COUNT(DCOUNT("experience", "employees",
    
    "[experience] = '" & [category] & "'"))
    
    FROM ...
    
    GROUP BY [category]
    Another thing too, is that you can simply add a category table for later use. This is advantage because you can throw in a one-to-many relationship with the employees table joining on "experience" or "category". Then in the future, all you have to do is query out the two tables with one inner join connecting them.

    Code works too, and is just as easy as going through the headaches of creating tables and making relay's.

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

Similar Threads

  1. calculated field from calculated field?
    By RedGoneWILD in forum Reports
    Replies: 5
    Last Post: 08-03-2010, 02:32 PM
  2. Calculated field
    By nashr1928 in forum Forms
    Replies: 9
    Last Post: 08-01-2010, 01:59 PM
  3. Calculated field
    By nashr1928 in forum Forms
    Replies: 3
    Last Post: 07-22-2010, 05:10 AM
  4. Formatting a Calculated Field
    By e_lady333 in forum Queries
    Replies: 0
    Last Post: 03-17-2010, 06:11 PM
  5. Error: "User-defined type not defined"
    By mastromb in forum Programming
    Replies: 10
    Last Post: 01-08-2010, 02:57 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