Can I use a variable to calculate a field in a query or form

E

ericsson

Hi

I want to calculate a field (or query) with a variable(integer(array)) . How
do I do.

I have declare a variable in a Module ,
"Public VarName(5,5) as integer" ,

and have used a Sub SetVar() to set values in it.
Sub SetVar()
For I = 1 to 5
For X = 1 to 5
VarName(I,X) = (I *I) +( X * 20)
Next X
Next I
End Sub

How can I then use the variable to calculate a field in a query, or in a
form.

Option:
Can I use it like this ?

Field1: Field2: Field3: CalculatedField:
25 1 3 Field1 * VarName(Field2, Field3)
= 25 * VarName(1,3)
12 2 4 Field1 * VarName(Field2, Field3)
=12 * VarName(2,4)

Please help me

//Lasse
 
D

Douglas J. Steele

You can't use variables like that in a query, but you can create a function
that passes back the value.

Something like the following untested air-code:

Function ReturnValue(X As Integer, Y As Integer) As Integer
ReturnValue = VarName(X, Y)
End Function

Your query would then be something like:

Field1: Field2: Field3: CalculatedField:
25 1 3 Field1 * ReturnValue(Field2,
Field3)
12 2 4 Field1 * ReturnValue(Field2,
Field3)
 

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