2

Please help.

=Does not work:

Function f()
    f = 1
End Function

Private Sub Button1_Click()
    k = Eval("f()")
End Sub

=Does not work:

Private Sub Button1_Click()
    с=1
    k = Eval("с")
End Sub

=Do work:

Function f()
    f = 1
End Function

Private Sub Button1_Click()
    k = f()
End Sub

=In help: The following example assumes that you have a series of 50 functions defined as A1, A2, and so on. This example uses the Eval function to call each function in the series.

Sub CallSeries()
    Dim intI As Integer
    For intI = 1 To 50
        Eval("A" & intI & "()")
    Next intI
End Sub 

How to make variant 1 work?

Thanks in advance.

++++++++++++++++++++++++++++

=UPDATE: The number of error I get with "Does not work" sections is 2425. "Can not find the name of the function." (or "Can not find the name of the expression." in the second case). Sorry for my English.

=UPDATE: When I try explicitly name the function in Eval:

 k = Eval("[Forms]![Form1].f()")

I get error 31005 - "Access can not calculate expression because there is a reference to "f"". I start to be suspicious of Access prohibiting use of user-defined functions and variables in Eval. Though help states opposite.

=UPDATE: Do work:

    Function f()
        f = 1
    End Function

    Private Sub Button1_Click()
        k = Eval("val(""551" & "9" & "6"")")
    End Sub

Very strange rules of double-quoting, as for me. But this does not solve my problem.

4
  • 1
    Please expand on "Does not work". Commented Jan 25, 2012 at 8:39
  • I do not really know how. That's all I have. Commented Jan 25, 2012 at 14:04
  • 2
    Do you get an error message? Does k=2? Does your computer catch on fire? What does "doesn't work" mean? Commented Jan 25, 2012 at 14:39
  • See updates and answer on joseph4tw's question for expanded and additional information. There are currently 3 different types of error. Commented Jan 25, 2012 at 15:56

2 Answers 2

5

The Eval function cannot access functions that are in Form modules. Place the function in an ordinary Module.

Sign up to request clarification or add additional context in comments.

Comments

1

There is one interesting fact. Eval() does not accept user variables as arguments, but accepts form controls data.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.