Problem with Eval function

Posted on 2008-11-19
Medium Priority
Last Modified: 2013-11-27
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

Question by:mlagrange
  • 4
  • 3
  • 2
  • +1
LVL 46

Expert Comment

ID: 22993755
The new Udf has only 3 letters?
Can you post it

Author Comment

ID: 22993782
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
LVL 46

Expert Comment

ID: 22993852
It could be a problem with the quotation marks ""
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.


Author Comment

ID: 22993896
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
LVL 75
ID: 22996730
Where is the Eval() function ?

LVL 75
ID: 22996745
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.


LVL 120

Accepted Solution

Rey Obrero (Capricorn1) earned 1000 total points
ID: 22996759
( Where is the Eval() function ? )

from VBA help type eval
LVL 75
ID: 22996815
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'!


Author Comment

ID: 22997346
>>> What happens if you just pass the arguments without the :=  syntax

Same error
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 1000 total points
ID: 22997374
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.


Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month13 days, 18 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question