Results 1 to 7 of 7
  1. #1
    DavidMichaelangelo is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    12

    Question Specify segment value based on criteria


    Is it possible to create a new field in an Access query that is filled in differently for different lines of criteria?

    In the image, you can see that I have two lines of criteria, two segments that I would like identified in the query results.
    Is there a way to create a new field in this query called "Segment" that populates with a different value based on which line of criteria returned the record?


    Click image for larger version. 

Name:	segments.png 
Views:	7 
Size:	4.3 KB 
ID:	20556
    Attached Thumbnails Attached Thumbnails segments.png   segments.jpg  

  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,652
    Looks like the only difference is the date field, so this type of thing:

    Segment: IIf(DateField >=..., 1, 2)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    DavidMichaelangelo is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    12
    Thanks. But I guess there's no way to specify a value in the interface since I already have the criteria laid out? I was just looking for a shortcut because I will be adding many more lines of criteria and I'm trying to avoid an enormous IIf statement . . .

  4. #4
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    My largest IIF statement so far was nested just over 10 times =\. You could create a custom function in a module to handle.

    Code:
    Function Segment(byval dtInput) as string
    
    select case dtInput
       case #1/1/2015# to #2/1/2015#
         Segment = "Example 1"
       case else
         Segment = "nothing found"
    end select
    end function
    in my experience these kind of functions can be slow, but it might get you out of a massive iif statement.

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Your question is not very clear. It would help if you provided examples or the data and what the expected results should be.
    Explain, in 4-5 sentences what you are trying to do.


    Is there a way to create a new field in this query called "Segment" that populates with a different value based on which line of criteria returned the record?
    Yes, probably.......
    If you looked at the results of the query, what calculations would you do to fill in the "Segment" column? ie - How do you calculate a 'Segment"?

  6. #6
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    I believe the user is trying to avoid IIF(datevalue=#value#,"value found",iif(datevalue>#value#,"value less",iif(datevalue<#value#,"value more","")))

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I think the goal is clear, I just don't think it can be done without some sort of function. There is no built-in function that will tell you which criteria a given record met to be included.
    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. Sum a column based on two criteria.
    By Degs29 in forum Queries
    Replies: 3
    Last Post: 09-24-2014, 02:32 PM
  2. Segment a string
    By Ruegen in forum Programming
    Replies: 2
    Last Post: 04-04-2014, 03:46 AM
  3. Criteria based on another field
    By jlclark4 in forum Queries
    Replies: 12
    Last Post: 02-14-2012, 12:29 PM
  4. Replies: 1
    Last Post: 06-12-2011, 07:08 AM
  5. IIF Criteria based on another table
    By BED in forum Queries
    Replies: 6
    Last Post: 11-24-2010, 01:55 PM

Tags for this Thread

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