Forum Discussion

MaxCA1000's avatar
MaxCA1000
Copper Contributor
Jan 15, 2022

Assigning Criteria Result to a Variable

In my query, I have a criteria requiring user input. I want to be able to assign that user input to a public variable and pass it to an iif expression in the same query, and also be able to call the variable in a function.

 

Can this be done?

  • MaxCA1000 

    you can try creating a Public function for the Parameter Criteria of your query.

    let say your table has a FirstName field and you want to filter it:

     

    global varParam As Variant

    public function getQueryParam()

    gstrParam = ""

    gstrParam = Inputbox("Input the name of person", , varParam)
    If IsNumeric(varParam) Then
    varParam = Val(varParam)
    End If

    getQueryParam = varParam

    end function

     

    your Global/Public variable is varParam.

     

  • arnel_gp's avatar
    arnel_gp
    Steel Contributor

    MaxCA1000 

    you can try creating a Public function for the Parameter Criteria of your query.

    let say your table has a FirstName field and you want to filter it:

     

    global varParam As Variant

    public function getQueryParam()

    gstrParam = ""

    gstrParam = Inputbox("Input the name of person", , varParam)
    If IsNumeric(varParam) Then
    varParam = Val(varParam)
    End If

    getQueryParam = varParam

    end function

     

    your Global/Public variable is varParam.

     

    • MaxCA1000's avatar
      MaxCA1000
      Copper Contributor
      Thank you for your suggestion. It's clever and I think it might work. I'll try it this weekend and let you know.
      • isladogs's avatar
        isladogs
        MVP
        You could also consider using a tempvar. These can be used directly in a query.
        No need for a user defined function

Resources