Problem with Eval function

Hello - I've been using the snip of code below in my application menus forever. "strExec" is the name of an Access object; when the user selects a menu option, it runs through the Select Case, doing the appropriate thing. If it's a user-defined function, it gets executed with the Eval() function in the Case Else.

Never had any problems up to now, but now I'm getting "The expression you entered contains invalid syntax." on this new UDF I just added. The only difference I can see is that this function contains arg's passed with "Optional ByVal"

This new function call works fine when exec'd from the Immediate Window.

It also works fine from my menu if I do not pass values for the "Optional ByVal" arg's:
     FormOpenStd("frmTest", "frmMainMenu")  <--- works
     FormOpenStd("frmTest", "frmMainMenu", , , , nvvarWndMode:=acWindowNormal, nvvarOpenArg:="CFrmID=frmMainMenu;Preset=0")modFrmSeriesProcs   <--- gets error

This is Access 2003

Any ideas?


Select Case Left$(strExec, 3)
        Case "tbl"
            DoCmd.OpenTable strExec
        Case "qry"
            DoCmd.OpenQuery strExec
        Case "frm"
            Me.Visible = 0
            DoCmd.OpenForm strExec
        Case "rpt"
            DoCmd.OpenReport strExec, acViewPreview
        Case "mac"
            DoCmd.RunMacro strExec
        Case Else
            Eval (strExec)
    End Select

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

The new Udf has only 3 letters?
Can you post it
mlagrangeAuthor Commented:
The Select Case works off the 1st 3 char's of strExec, the Case Else uses the whole thing

And I left some junk on the end of the "gets error" example; sorry about that; that's not part of the call, obviously, it was in the Immediate Window
It could be a problem with the quotation marks ""
10 Holiday Gifts Perfect for Your Favorite Geeks

Still have some holiday shopping to do for the geeks in your life? While toys, clothing, games, and gift cards are still viable options for your friends and family, there’s more reason than ever to consider gadgets and software.

mlagrangeAuthor Commented:
I call other other UDF's from this menu that have quotation marks; they work fine.

And this new UDF works fine, with the q's around the first 2 arg's, as long as I don't try to pass any of the Optional ByVal arg's
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Where is the Eval() function ?

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Instead of

     FormOpenStd("frmTest", "frmMainMenu", , , , nvvarWndMode:=acWindowNormal, nvvarOpenArg:="CFrmID=frmMainMenu;Preset=0")modFrmSeriesProcs   <--- gets error

What happens if you just pass the arguments without the :=  syntax.  Just pass the values.


Rey Obrero (Capricorn1)Commented:
( Where is the Eval() function ? )

from VBA help type eval

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
LOL ... that's *not* what I was asking!  At first I didn't see it in the code, but I do now.  And the Q was 'Where', not 'What'!

mlagrangeAuthor Commented:
>>> What happens if you just pass the arguments without the :=  syntax

Same error
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
The argument inside the Eval() function must evaluate to a String.  Put a break point on the Eval() ... and see if there is a proper String as an argument, ie ... no extra quotes, double quotes, etc.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.