Using a Variable as a query Expression Value

G

Guest

Hi,
I've been reading a past post "Passing a Variable As Query Criteria" Ofer -
Can anyone explain this a bit further. I'm afraid I'm not very good with
functions and always get a bit lost on this.
The original response was:
"You can create a Function that return the value of the variable, and use
this
function in the query
Global VarName as Double
Function FunctionName () as Double
FunctionName = VarName
End Function

Both, function and variable should be defined in a module, and not in a form
or report"

I have done this, but how do you call the Variable/function from the query
itself?

Basically I want to create an append query which will write multiple records
based upon a single value which I have stored from a previous form.

So the query would be something like:

Selected, PupilID, ExamID:[Variable] (it's this last bit I can't quite get).

Thanks for any help in advance.

Wendy
 
G

Guest

Actually, I've done everything as said.

Global ExamNum As Integer

Function GetExamID() As Integer
GetExamID = ExamNum
End Function

and the query is set to ExamID:GetExamID()

I get an error: "Undefined function "GetExamID()"...I'm doing something
stupid and annoyingly my post went to general questions instead of queries
(sorry)
 
G

Guest

Hi Peeps, it's okay, I just worked it out. Me being dopey. Sorry to trouble
yall.

Wendywo said:
Actually, I've done everything as said.

Global ExamNum As Integer

Function GetExamID() As Integer
GetExamID = ExamNum
End Function

and the query is set to ExamID:GetExamID()

I get an error: "Undefined function "GetExamID()"...I'm doing something
stupid and annoyingly my post went to general questions instead of queries
(sorry)

Wendywo said:
Hi,
I've been reading a past post "Passing a Variable As Query Criteria" Ofer -
Can anyone explain this a bit further. I'm afraid I'm not very good with
functions and always get a bit lost on this.
The original response was:
"You can create a Function that return the value of the variable, and use
this
function in the query
Global VarName as Double
Function FunctionName () as Double
FunctionName = VarName
End Function

Both, function and variable should be defined in a module, and not in a form
or report"

I have done this, but how do you call the Variable/function from the query
itself?

Basically I want to create an append query which will write multiple records
based upon a single value which I have stored from a previous form.

So the query would be something like:

Selected, PupilID, ExamID:[Variable] (it's this last bit I can't quite get).

Thanks for any help in advance.

Wendy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top