none
Compile error: Expected list separator or ) RRS feed

  • Question

  • Hello,

    Please, advise me where is the error in the following code:

    Function Filter(Number As Integer, Name As String)
       Select Case Name
        Case "aaa"
            Filter = True
        Case "bbb"
            Filter = True
        Case Else
            Select Case Number
                Case 79001
                    Filter = True
                Case Else
                    Filter = False
            End Select
        End Select
    End Function

    Thank you in advance!


    • Edited by KateStsv Friday, May 26, 2017 10:26 PM
    Friday, May 26, 2017 10:26 PM

Answers

  • Function ABCDEFG(Number1 As Integer, Name1 As String)

        ....

            Select Case Number1
                Case 79001

    Hi Kate,

    You can use nested Select Case statements, as you have already demonstrated in your example.

    The problem lies in  Case 79001. This value is too large for an Integer. You can better use the Long type..

    You can further simplify your code:

    Function ABCDEFG(Number1 As Long, Name1 As String) As Boolean
        Select Case Name1
        Case "aaa", "bbb": ABCDEFG = True
        Case Else
            Select Case Number1
            Case 79001: ABCDEFG = True
            End Select
        End Select
     End Function
    

    as this function defaults False as result.

    Imb.

    • Marked as answer by KateStsv Saturday, May 27, 2017 10:38 PM
    Saturday, May 27, 2017 5:58 AM
  • ABCDEFG(20001;"gh")

    "Compile error: Expected list separator or )"

    Hi Kate,

    The arguments are to be separated by a comma:

        boolean_result = ABCDEFG(20001,"gh")

    Imb.

    • Marked as answer by KateStsv Saturday, May 27, 2017 10:38 PM
    Saturday, May 27, 2017 8:17 PM

All replies

  • Not sure if you can build a case statement within another one, then again, I've never tried it.

    That said, Filter is a Reserved Word and should never be used to name Objects, Fields, Controls, VBA procedures, VBA variables...


    Daniel Pineault, 2010-2016 Microsoft MVP
    Professional Support: http://www.cardaconsultants.com
    MS Access Tips and Code Samples: http://www.devhut.net

    Saturday, May 27, 2017 12:52 AM
  • Thank you, Daniel!

    But the word "Filter" is not the reason of the compile error. The following function dosn't work either:

    Function ABCDEFG(Number1 As Integer, Name1 As String)
       Select Case Name1
        Case "aaa"
            ABCDEFG = True
        Case "bbb"
            ABCDEFG = True
        Case Else
            Select Case Number1
                Case 79001
                    ABCDEFG = True
                Case Else
                    ABCDEFG = False
            End Select
        End Select
    End Function

    Saturday, May 27, 2017 5:00 AM
  • Function ABCDEFG(Number1 As Integer, Name1 As String)

        ....

            Select Case Number1
                Case 79001

    Hi Kate,

    You can use nested Select Case statements, as you have already demonstrated in your example.

    The problem lies in  Case 79001. This value is too large for an Integer. You can better use the Long type..

    You can further simplify your code:

    Function ABCDEFG(Number1 As Long, Name1 As String) As Boolean
        Select Case Name1
        Case "aaa", "bbb": ABCDEFG = True
        Case Else
            Select Case Number1
            Case 79001: ABCDEFG = True
            End Select
        End Select
     End Function
    

    as this function defaults False as result.

    Imb.

    • Marked as answer by KateStsv Saturday, May 27, 2017 10:38 PM
    Saturday, May 27, 2017 5:58 AM
  • Thank you very much for your reply!

    I tried the suggested code but I still get the following error in the immediate window:

    --------------------------------------------

    ABCDEFG(20001;"gh")

    "Compile error: Expected list separator or )"

    --------------------------------------------

    I am in despair... :(((

    Saturday, May 27, 2017 7:57 PM
  • ABCDEFG(20001;"gh")

    "Compile error: Expected list separator or )"

    Hi Kate,

    The arguments are to be separated by a comma:

        boolean_result = ABCDEFG(20001,"gh")

    Imb.

    • Marked as answer by KateStsv Saturday, May 27, 2017 10:38 PM
    Saturday, May 27, 2017 8:17 PM
  • Thank you very much! :))
    Saturday, May 27, 2017 10:37 PM