Results 1 to 3 of 3
  1. #1
    vicsaccess's Avatar
    vicsaccess is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    451

    select case with multiple criteria?

    I couldn't find anything on this and ended up writing a nested if to do it, but would still like to know if it is possible. What I was after was to test both w and h together for true but could not get it to test for the h. It kept finding the first w that was true and returning that value instead of looking at h. Is it possible with a case select to test for both?

    Code:
    Public Function index(cr As Integer, h As Integer, pr As Integer, w As Integer) As Integer
        Dim g As Integer
        
        If IsNull(h) Then '''test for null, if so asign a value'''
            g = 4         '''test for 4 instead of null'''
        Else
            g = h
        End If
        
        Select Case w And g
            Case w = 5 And g = 1
                index = 6
            Case w = 5 And g = 2
                index = 5
            Case w = 5 And g = 1
                index = 4
            Case w = 6 And g = 4
                index = 3
            Case w = 7 And g = 4
                index = 2
            Case w = 6 And g = 1
                index = 1
            Case w = 6 And g = 2
                index = 7
            Case w = 6 And g = 3
                index = 8
            Case w = 1 And g = 4
                index = 9
            Case w = 2 And g = 4
                index = 10
            Case w = 3 And g = 4
                index = 11
            Case w = 4 And g = 4
                index = 12
            Case Else
                index = "else"
        End Select
    End Function
    Example, w was 5 and h was 2 would return 6 instead of 5.

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    I don't see where your code does this?

    What I was after was to test both w and h together for true
    Perhaps you could tell readers in plain English what you are trying to do. Forget the code and just overview the requirement.

  3. #3
    vicsaccess's Avatar
    vicsaccess is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Apr 2015
    Posts
    451
    trying to test
    if w is 5 and g is 1 then return index as 6
    if w is 5 and g is 2 then return index as 5
    if w is 5 and g is 3 then return index as 4, this one is typed wrong in the code.
    the nested if that replaced it was
    Code:
        If (w) = 5 And (g) = 1 Then 
            index = 1
        ElseIf (w) = 5 And (g) = 2 Then 
            index = 2
        ElseIf (w) = 5 And (g) = 3 Then 
            index = 3
    this is working just fine, just curious if it was possible with a case select and how?

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

Similar Threads

  1. Pl sql case select
    By mrmmickle1 in forum Queries
    Replies: 1
    Last Post: 11-17-2015, 11:14 PM
  2. Replies: 3
    Last Post: 10-27-2014, 07:37 AM
  3. Select case help
    By killermonkey in forum Programming
    Replies: 7
    Last Post: 10-25-2013, 05:09 PM
  4. Replies: 2
    Last Post: 04-10-2013, 03:54 PM
  5. Replies: 0
    Last Post: 02-28-2011, 09:46 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