Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a function as a query parameter

Status
Not open for further replies.

emik

MIS
Joined
Jul 24, 2006
Messages
80
Location
CA
The main purpose is the prompt the user with an input box, they enter a value and I pass that value to a query parameter. I have done programs in the past that worked, but I had to create 2 functions, the first to accept the value and pass it to the second. The second was then used as the parameter. It seems I should only need 1 function to get a value and pass it. Am I doing something wrong?

Public Function pass_parameter(test as double) as double
pass_parameter = test
End Function

In the query under the field I have pass_parameter()

I get this error:
"Wrong number of arguements used with function in query expression."




 
Your error means exactly what it says. "pass_parameter" requires one argument (Test) to be supplied to it and you haven't supplied any arguments in your call.

I'm not sure what you're trying to do exactly. You mention "... a query parameter ..." which is something like
Code:
Select fld1, fld2, fld3 From myTable

Where fld1 < [red][Enter fld1 Value][/red]
and the part in [red]red[/red] is a query parameter. If you wanted to use a Function where the parameter appears then you might do something like
Code:
Select fld1, fld2, fld3 From myTable

Where fld1 < [red]Fld1EntryValue()[/red]
where Fld1EntryValue might be
Code:
Public Function Fld1EntryValue() As Long
   Fld1EntryValue = Year(Date()) \ 11
End Function

Can you provide a bit more detail about what you are doing?

 
Thanks for the reply.

Ok here is a better description.
This is an sample table with a similiar idea:

Name | Company | Value
Mike | CompanyA | 500
Mike | CompanyA | 450
Paul | CompanyB | 600
Adam | CompanyC | 700
GROUP BY GROUP BY SUM

The type of data I'm working with needs to be grouped because it is similiar to transactions, so how much total is "Mike"'s value.

I want an input box where the user is prompted to enter a minimum value, so if the user enters "650" it should return by passing that 650 to a function used as criteria in the query (greater than).

Mike | CompanyA | 950
Adam | CompanyC | 700

The reason I want to use a function is because I want more code control, verify what they enter a valid number and store it to be used in a report later "All values with a minimum value of X" type of thing.

 
I still can't get it to work...

In my code I have:

Call FunctionName(Var_1)

The function is:

Public Function FunctionName(Var_2) as long
FunctionName = Var_2
End Function

In the Query criteria I have:

>FunctionName(Var_2)

When I do a step through it assigns the value to the function but right when I open the report it seems it execute the function again and then I get a type mismatch FunctionName = "Var_2" (the string, not the value).

Ignoring my situation, how do you have the user enter a value, pass that value to a function and use that function as criteria for a query?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top