• Passing a boolean value to a parameter query

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Passing a boolean value to a parameter query

    Author
    Topic
    #463863

    I have an append query to a temp table which filter postal codes based on Clients being Active or Inactive. I am recording this true/false value to a text box on a form then passing the value to the parameter in the query. The choice of value is determined by a three-value option group 1 = false, 2, = true, 3 = either true or false.

    I use a function to return the value needed to the parameter. If I select options 1 or 2 the parameter is passed properly. If I select option 3, I’m only getting one value.

    Clearly the function is not passing information that the parameter can understand.
    If, in my function, Case 1 = false and case 2 = true how do I pass the value case 3 = True Or False

    I suspect one problem is that my function and the returned value is boolean but I need three possibilities, not two. Here’s the function. I’m writing in a hurry, so I can post back if there is still insufficient information. (PS I know strFilter is a goofy name for a Boolean. I adapted it from another use where it was a string. The use of null for case three was a failed attempt to get around this.)

    Private Function FilterName(intVal As Integer) As Boolean

    intVal = Me.OptAct.Value

    Dim strFilter As Boolean

    Select Case intVal
    Case 1
    Let strFilter = False
    Case 2
    Let strFilter = True
    Case 3
    Let strFilter = Null
    End Select

    FilterName = strFilter

    End Function

    Viewing 0 reply threads
    Author
    Replies
    • #1185466

      I think you answered your own question.
      A boolean value by default is either TRUE or FALSE. Not NULL.
      You are using an Integer with 3 values.
      Either change the parameter to be an integer and adjust query.
      Realistically you need the filter that gets used by the query to only have a filter if true or false and no filter otherwise.
      The function is boolean so it cannot retyrn a NULL.
      What is the query that receives the function result.

      • #1185481

        I think you answered your own question.
        A boolean value by default is either TRUE or FALSE. Not NULL.
        You are using an Integer with 3 values.
        Either change the parameter to be an integer and adjust query.
        Realistically you need the filter that gets used by the query to only have a filter if true or false and no filter otherwise.
        The function is boolean so it cannot retyrn a NULL.
        What is the query that receives the function result.

        I was going at it from the wrong direction. Rather than trying to use a saved query and pass “True or False” to it as a parameter, I am running the query in VBA with Docmd.RunSQL and appending the appropriate WHERE condition via my function.
        Thanks for the reply.

    Viewing 0 reply threads
    Reply To: Passing a boolean value to a parameter query

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: