Why does this code not work?

M

mscertified

The following code gives me 'function not found'. According to the Help page
for Eval function, it should work?

Private Sub butRun_Click()
Dim strMod As String
strMod = "Gumbo"
Eval (strMod & "()") <========= fails here
End Sub

Private Function Gumbo() As Boolean
MsgBox "Gumbo"
Gumbo = True
End Function
 
D

Dirk Goldgar

mscertified said:
The following code gives me 'function not found'. According to the Help
page
for Eval function, it should work?

Private Sub butRun_Click()
Dim strMod As String
strMod = "Gumbo"
Eval (strMod & "()") <========= fails here
End Sub

Private Function Gumbo() As Boolean
MsgBox "Gumbo"
Gumbo = True
End Function


I'm inclined to think the function Gumbo must be Public. Does that work?
 
M

mscertified

No, it gives the same error...
"The expression you entered has a function name that Microsoft Office Access
can't find."
 
D

Dirk Goldgar

mscertified said:
No, it gives the same error...
"The expression you entered has a function name that Microsoft Office
Access
can't find."


Where are these routines defined? In a standard module or in a form module?
If this is a form module, any public procedure on the form is going to have
to be qualified with a reference to the form. I've tried this:

Dim strMod As String
strMod = "Gumbo"
Eval ("Forms!" & Me.Name & "." & strMod & "()")

.... and it almost works, but it give an error message after displaying the
message box.
 
D

Dirk Goldgar

Dirk Goldgar said:
If this is a form module, any public procedure on the form is going to
have to be qualified with a reference to the form. I've tried this:

Dim strMod As String
strMod = "Gumbo"
Eval ("Forms!" & Me.Name & "." & strMod & "()")

... and it almost works, but it give an error message after displaying the
message box.


For what it's worth, the following clumsy workaround serves to avoid that
error message while allowing others:

'----- start of example code -----
On Error GoTo Err_Handler

Dim strMod As String

strMod = "Gumbo"
Eval ("Forms!" & Me.Name & "." & strMod & "()")

Exit_Point:
Exit Sub

Err_Handler:
If Err.Number <> 2431 Then
Err.Raise Err.Number, Err.Source, Err.Description, _
Err.HelpFile, Err.HelpContext
End If
Resume Exit_Point

'----- end of example code -----

But I haven't been able to find a way to avoid raising the error at all. I
tried making Gumbo a public property of the form, and that eliminated the
error but resulted in Gumbo being called twice for some reason.
 
J

J_Goddard via AccessMonster.com

Hi -

In Access 2000 - I copied your code to a test module; with the "Private" in
the declaration, it did not work. Once I took the "Private" off, it ran fine,
even when I closed the module.

It must be something about the way Eval works, but I don't use it - Experts?


John
 
P

Pieter Wijnen

Private is the key, Eval works only with Public functions
Done that, been there, seen the movie

Pieter
 

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