Results 1 to 4 of 4
  1. #1
    P5C768 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2009
    Location
    Denver, CO
    Posts
    95

    Use Select Case to Consolidate Switch Function

    I need to consolidate 5 fields stored in a table into 29 different categories (eventually to be used in a cross-tab query to generate counts of each category). I'm limited in using switch and/ or iif statements because of the number of nested statements I would need.



    Is there a way to do this using by creating a function and using select case? I'm not sure how to reference multiple fields in a table. Thanks!

    Here is an example of what I was origionally thinking of:

    Code:
    test: Switch([ORG Change]="Change" And [Class Change]
    ="Change" And [Range Maximum]="Down" And [Salary Change]
    ="Down","Demotion to Another Deartment with Pay Decrease",
    [ORG Change]="Change" And [Class Change]="Change" And 
    [Range Maximum]="Down" And [Salary Change]="No Change",
    "Demotion to Another Deartment with No Pay Change",
    [ORG Change]="Change" And [Class Change]="Change" And 
    [Range Maximum]="Down" And [Salary Change]="Up",
    "Demotion to Another Deartment with Pay Increase",
    [ORG Change]="Change" And [Class Change]="Change" And 
    [Range Maximum]="No Change" And [Salary Change]="Down",
    "Transfer to Another Department with Pay Decrease",
    [ORG Change]="Change" And [Class Change]="Change" And 
    [Range Maximum]="No Change" And [Salary Change]=
    "No Change","Transfer to Another Department with No Pay Change",
    [ORG Change]="Change" And [Class Change]="Change" And 
    [Range Maximum]="No Change" And [Salary Change]="Up",
    "Transfer to Another Department with Pay Increase")

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,524
    Sure; you'd have the function accept your 4 values (if I counted right) as input parameters, and output the text. Another option would be a table with 5 fields, the 4 parameter fields plus the output. Then you could get the value with a lookup or join.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    P5C768 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Aug 2009
    Location
    Denver, CO
    Posts
    95
    How do you set inidividual table values as inputs into a funtion? So if I'm understanding you right I could then just run a cross-tab query and count the occurence of each value in the table? I have approx. 40k records, would I need to store the values the function creates in a table?

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,524
    Well, you already have the values in the query, so you'd just pass them. In design view of the query it would look like:

    test: YourFunctionName([ORG Change], [Class Change], [Range Maximum], [Salary Change])

    The function would use those values and If/Then or Select/Case to evaluate the inputs and return the appropriate string. The table I had in mind would look like:

    Code:
    [ORG Change]  [Class Change]  [Range Maximum]  [Salary Change]   ReturnValue
    "Change" "Change" "Down" "Down"       "Demotion to Another Deartment with Pay Decrease"
    "Change" "Change" "Down" "No Change"  "Demotion to Another Deartment with No Pay Change"
    With all the potential combinations listed. Theoretically you could then join that table on the 4 fields and get the resulting string.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. count and switch function in same select query
    By sandlucky in forum Queries
    Replies: 2
    Last Post: 04-08-2011, 11:16 PM
  2. Using SQL switch function MS Access
    By sandlucky in forum Queries
    Replies: 18
    Last Post: 03-31-2011, 08:49 AM
  3. Select Query in Switch Function
    By sandlucky in forum Queries
    Replies: 0
    Last Post: 03-30-2011, 04:54 AM
  4. Combine switch function and Wild cards together
    By sandlucky in forum Queries
    Replies: 0
    Last Post: 03-28-2011, 11:51 PM
  5. Case or Switch in an update statement
    By allenjasonbrown@gmail.com in forum Queries
    Replies: 7
    Last Post: 11-17-2010, 01:49 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