473,394 Members | 1,971 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Eval error 2431

ray
I am calling a function using eval. It runs in a form module, in
response to a button OnClick.

strCall = "Forms!frmSchedule.eval" & strSName(0) & "()"
On Error Resume Next
n = Eval(strCall)
For the purposes of testing, strSName(0) is always = "LoanType"

The function evalLoanType runs ok, and doesn't generate an error.

However, when control return to the calling routing above, n is always
Empty and Err.Number = 2431, that is, "The expression you entered
contains invalid syntax."

Could anybody help me resolve this so that it returns the correct value
of the function, and doesn't produce an error? The error value is a
problem because I still need to trap situations where a function named
by the variable doesn't exist.

Thanks,

Ray


Function evalLoanType() As Integer
On Error GoTo eLT_Err
If Not PositiveInteger(Me!ScheduleNoOfParties) Then
MsgBox "Please enter the Number of Parties.", vbInformation, "Data
Entry"
evalLoanType= -1
Else
evalLoanType= 0
End If
eLT_Exit:
Exit Function
eLT_Err:
MsgBox Err.Description & vbCrLf & vbCrLf & "Cannot evaluate number
of parties." Resume eLT_Exit
End Function

May 29 '06 #1
14 4038
OTTOMH

Public Function evalLoanType() As Integer

n = Form_frmSchedule.evalLoanType()

May 29 '06 #2
ray
Thanks Lyle!

Sadly though, it didn't woik. Eval seems to run the function only if
you have it referenced as Forms!FormName.functionname().

If you have anything else OTTOYH I would be glad to hear it. Or
OTTOAE'sH for that matter,

Ray

May 30 '06 #3
I appreciate that you have tired and reported but I did not write about
Eval. I wrote about

1.ensuring the function is Public

2. setting the value of n to that returned by
Form_frmSchedule.evalLoanType() .

Eval is a silly little hack for non-programmers to use. In however many
years (14?) with Access I have never used Eval (TTBOMR).

May 30 '06 #4
Unless you are using A97, you want to use CallByName
instead of using Eval:

set frm = Forms("frmSchedule")
CallByName
frm,
"evalLoanType",
VbMethod

you don't want to do use eval because a bug in the
current implementation of eval causes it to evaluate
object methods twice when run once.

You can only call a form method if it is public,
and only if the form is open.

(david)


<ra*@aic.net.au> wrote in message
news:11**********************@38g2000cwa.googlegro ups.com...
I am calling a function using eval. It runs in a form module, in
response to a button OnClick.

strCall = "Forms!frmSchedule.eval" & strSName(0) & "()"
On Error Resume Next
n = Eval(strCall)
For the purposes of testing, strSName(0) is always = "LoanType"

The function evalLoanType runs ok, and doesn't generate an error.

However, when control return to the calling routing above, n is always
Empty and Err.Number = 2431, that is, "The expression you entered
contains invalid syntax."

Could anybody help me resolve this so that it returns the correct value
of the function, and doesn't produce an error? The error value is a
problem because I still need to trap situations where a function named
by the variable doesn't exist.

Thanks,

Ray


Function evalLoanType() As Integer
On Error GoTo eLT_Err
If Not PositiveInteger(Me!ScheduleNoOfParties) Then
MsgBox "Please enter the Number of Parties.", vbInformation, "Data
Entry"
evalLoanType= -1
Else
evalLoanType= 0
End If
eLT_Exit:
Exit Function
eLT_Err:
MsgBox Err.Description & vbCrLf & vbCrLf & "Cannot evaluate number
of parties." Resume eLT_Exit
End Function

May 30 '06 #5
ray
Thanks again, folks.

I have been working in Access for a similar length of time to Lyle and
avoided Eval simply because it looked a bit of an orphan. However, the
current situation called for function names passed as strings. Lyle, I
certainly did try making the function Public, and changed the
referencing as you suggested - I just didn't cotton on to the
distinction that you had made with regard to calling the function. I
take all suggestions made in this newsgroup seriously and try them out
as best as I understand them - comp.databases.ms-access is a major
lifeline for me in my business and I try and drop a few suggestions or
solutions back in when I am capable.

Fabulously, though, CallByName, which I had never come across before,
works an absolute treat. Thanks David!

Ray

Jun 1 '06 #6
How long has CallByName been in Access? That's grand!

Thanks David!
Jun 1 '06 #7

<w_a_n_n_a_l_l_ -@-_s_b_c_g_l_o_b_a_l._n_e_t> wrote in message
news:EX********************@newssvr29.news.prodigy .net...
How long has CallByName been in Access? That's grand!

Thanks David!


Yes, the help system in Access is pretty helpless... I would never have
found it, but for 'Schof' in microsoft.public.access. I think it was better
known to VB programmers.
(david)
Jun 1 '06 #8
david epsom dot com dot au wrote:
Unless you are using A97, you want to use CallByName
instead of using Eval:

set frm = Forms("frmSchedule")
CallByName
frm,
"evalLoanType",
VbMethod

you don't want to do use eval because a bug in the
current implementation of eval causes it to evaluate
object methods twice when run once.

You can only call a form method if it is public,
and only if the form is open.


Please, try

CallByName Form_frmSchedule, "evalLoanType", VbMethod

when frmSchedule is not open and no reference/pointer to it has been
initialised.

Jun 1 '06 #9
>
On 31-May-2006, "david epsom dot com dot au" <david@epsomdotcomdotau> wrote:
the help system in Access is pretty helpless...

No argument there. It was excellent back in 2.0 and has been going downhill
ever since.

In 2.0 you could actually learn how to develop by using the help file. Its
only sin was that it mixed user and developer help, but even that was done
in a fairly predictable manner. As the help has moved more and more in the
modern direction it has suffered tremendously IMO.
Jun 1 '06 #10
Wow! Thanks for this info. Both of these worked:

1. call forms("form2").sayhello
2. callbyname form_form2, "sayhello",VbMethod

I made form2, with a public function named SayHello().

If I open the form, then line 1 works just fine. (All of this is in the
immediate window of course.) Whether the form is open or closed, line 2
works just fine.

Slick.
Jun 1 '06 #11

Rick Wannall wrote:
Wow! Thanks for this info. Both of these worked:

1. call forms("form2").sayhello
2. callbyname form_form2, "sayhello",VbMethod

I made form2, with a public function named SayHello().

If I open the form, then line 1 works just fine. (All of this is in the
immediate window of course.) Whether the form is open or closed, line 2
works just fine.

Slick.


Form_Form2.sayhello

Jun 1 '06 #12
Cool. Thanks.
Jun 1 '06 #13
Yes, I was wrong.

(david)

"Lyle Fairfield" <ly***********@aim.com> wrote in message
news:11**********************@c74g2000cwc.googlegr oups.com...
david epsom dot com dot au wrote:
Unless you are using A97, you want to use CallByName
instead of using Eval:

set frm = Forms("frmSchedule")
CallByName
frm,
"evalLoanType",
VbMethod

you don't want to do use eval because a bug in the
current implementation of eval causes it to evaluate
object methods twice when run once.

You can only call a form method if it is public,
and only if the form is open.


Please, try

CallByName Form_frmSchedule, "evalLoanType", VbMethod

when frmSchedule is not open and no reference/pointer to it has been
initialised.

Jun 2 '06 #14
david epsom dot com dot au wrote:
Yes, I was wrong.


Regardless the information you gave was helpful. I had not experimented
with CallByName before your post. It has an advantage over calling a
form's public methods or using its public properties directly as in
Form_Form1.Method1.

CallByName Form_Form1, "Method1", VbMethod, "Parameter1"
opens Form1(if it's not already open), runs Qwerty and closes Form1(if
it opened it).

Form_Form1.Method1does not do the closing and this must be looked after
by the coder.

I note that either of these is useful for dealing with subforms and
avoids the lengthy form.control.form whatever syntax; the simple
Form_Form1. syntax provides us with Intellisense when coding while
CallByName I think, does not.

It may be worthwhile to note that if one opens an array of instances of
a form each method will open a new distinct instance of the form to do
its work

Thanks for telling us about this; I had missed it.

Jun 2 '06 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Reply Via Newsgroup | last post by:
This might sound sad... someone requesting a disertation on the 'eval' statement... but... I've been reading someone else's post - they had a huge calander like script and a handful of folk cursed...
12
by: knocte | last post by:
Hello. I have always thought that the eval() function was very flexible and useful. If I use it, I can define functions at runtime!! However, I have found a case where eval() does not work...
2
by: Kent Eilers | last post by:
ok - trying to use eval() to abstract out an update operation i need to perform. I wanted to use the eval() function to avoid HARD CODING the field names that need to be updated in the target...
0
by: Michelle Keys | last post by:
Subject: DataBinder.Eval Error! Server Error in '/MSPOS' Application. ------------------------------------------------------------------------ -------- DataBinder.Eval:...
18
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My...
0
by: coderpunk | last post by:
The system has multiple virtuals on it, one of them has some broken code that is being run through eval() at a fairly regular rate, the logs show a PHP Parse Error in the eval()'d code. A...
4
by: Jm lists | last post by:
Hello members, I want to know does the "eval" in python have the same features as in Perl (capture errors)? For example,in perl I can wrote: $re = eval { 1 / 0 }; Though 1/0 is a fatal...
6
by: vasudevram | last post by:
Hi group, Question: Do eval() and exec not accept a function definition? (like 'def foo: pass) ? I wrote a function to generate other functions using something like eval("def foo: ....") but...
5
by: Smiley | last post by:
I'm fooling around with using Eval and trying to manipulate a few things. I ran into a couple of weird results. First of all, in one place I used the following code: $filestring =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.