EVAL

G

Guest

Hi,

I'm designing a Form in Access 2003 and where a given event takes place, I
call up a Function. Basically, the Function holds 2 arguments. One of them is
the name of the field in the form to change, the other one is the value.

Here's the function:

Function LastUpdate(nField, TempVar)
Dim strCtl As String

strCtl = "Forms![Pipeline]![" & nField & "]=" & TempVar
Eval (strCtl)
Me.[ProjectCode].SetFocus

End Function

Here's how I call it:

Call LastUpdate("GoGet", iGoget)

In the end, the [GoGet] field doesn't store the value that I pass through
the TempVar variable.
In Debug Mode, I can see that the strCtl is ok but somehow the EVAL function
isn't producing the effect that I want.

Anyone?

Thanks
Antonio
 
D

Dirk Goldgar

Antonio said:
Hi,

I'm designing a Form in Access 2003 and where a given event takes
place, I call up a Function. Basically, the Function holds 2
arguments. One of them is the name of the field in the form to
change, the other one is the value.

Here's the function:

Function LastUpdate(nField, TempVar)
Dim strCtl As String

strCtl = "Forms![Pipeline]![" & nField & "]=" & TempVar
Eval (strCtl)
Me.[ProjectCode].SetFocus

End Function

Here's how I call it:

Call LastUpdate("GoGet", iGoget)

In the end, the [GoGet] field doesn't store the value that I pass
through the TempVar variable.
In Debug Mode, I can see that the strCtl is ok but somehow the EVAL
function isn't producing the effect that I want.

Anyone?

Thanks
Antonio

The Eval function can't be used to perform an assignment statement like
that -- it can only be used to evaluate an expression that returns a
value. But it seems you could just rewrite your code like this:

'----- start of revised code -----
Function LastUpdate(nField, TempVar)

Forms!Pipeline.Controls(nField) = TempVar
Me.[ProjectCode].SetFocus

End Function
'----- end of revised code -----
 
G

Guest

THANKS!


Dirk Goldgar said:
Antonio said:
Hi,

I'm designing a Form in Access 2003 and where a given event takes
place, I call up a Function. Basically, the Function holds 2
arguments. One of them is the name of the field in the form to
change, the other one is the value.

Here's the function:

Function LastUpdate(nField, TempVar)
Dim strCtl As String

strCtl = "Forms![Pipeline]![" & nField & "]=" & TempVar
Eval (strCtl)
Me.[ProjectCode].SetFocus

End Function

Here's how I call it:

Call LastUpdate("GoGet", iGoget)

In the end, the [GoGet] field doesn't store the value that I pass
through the TempVar variable.
In Debug Mode, I can see that the strCtl is ok but somehow the EVAL
function isn't producing the effect that I want.

Anyone?

Thanks
Antonio

The Eval function can't be used to perform an assignment statement like
that -- it can only be used to evaluate an expression that returns a
value. But it seems you could just rewrite your code like this:

'----- start of revised code -----
Function LastUpdate(nField, TempVar)

Forms!Pipeline.Controls(nField) = TempVar
Me.[ProjectCode].SetFocus

End Function
'----- end of revised code -----

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
L

Larry Linson

The Eval function can't be used to
perform an assignment statement like
that -- it can only be used to evaluate
an expression that returns a
value.

But, a very nice feature is that, because Functions, by definition, return a
value, you can execute a Function, which might well do something in addition
to just returning a value.

Larry Linson
Microsoft Access MVP
 
D

Dirk Goldgar

Larry Linson said:
But, a very nice feature is that, because Functions, by definition,
return a value, you can execute a Function, which might well do
something in addition to just returning a value.

Indeed yes! The function doesn't even have to return any meaningful
value -- it can return Null, either explicitly or by default. When
using Eval this way, you do have to be sure to include the parentheses
after the function name, even if the function doesn't require any
arguments. For example,

v = Eval("MyFunction()")
 

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