Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Eval function not work with multiple parameters.

Status
Not open for further replies.

TechRider

IS-IT--Management
Jan 7, 2002
6
US
Anyone can help me on this?

I am running Access 2000 and trying to use the Eval function to pass a string and have it execute what the string evauates to. It seems when I pass it multiple parameters within that string it doesn't work. I have 2 code snippets below to show what I mean.

Ideas anyone? Need more info, let me know.

Thanks, Mark


'====Snip 1====
Private Sub Command0_Click()


Eval ("MsgBox(""msg"")")
'Works passing single parameter
' string evaluates to: MsgBox("msg")


Eval ("MsgBox(""msg"", , ""title"")")
' Doesn't work, multiple parameters-- error 2431
' string evaluates to: MsgBox("msg", , "title")

End Sub



'===Snip2===
Private Sub Command0_Click()
Dim x As String


x = "DoCmd.OpenReport (""R1"")"

Debug.Print x
Eval (x)
' Works – single parameter


x = "DoCmd.OpenReport (""R1"", 2)" ' acPreview = 2

Debug.Print x
Eval (x)
'Not work

End Sub
 
What are you trying to do with this??
DougP, MCP
 
DougP,
Thanks for the response.

I am creating a hierarchical switchboard for an application I wrote. I am using a Treeview object and populating it using the data I have put in a table. Some of the data includes a text field which contains the command I want to be run when a user clicks on one of the nodes. The whole thing works beautifully with the exception of when one of my commands has multiple parameters such as

msgbox(“whatever”, , “the Title”)
Or docmd.openreport(“Report1”,acpreview)

All of the other commands work such as

Docmd.beep
Msgbox (“Not enabled yet”)


I didn’t want to code all of the possible commands I might want to use. And, I wanted to leave it somewhat open so that without touching the code, I could use the switchboard for other applications. I realize there’s lots of ways to accomplish what I’m trying to do, but I also wanted to do it this way for the mental exercise.

The examples I included with my previous post are the lowest level of code which will recreate the problem I am running into. It doesn’t really do anything useful.

That’s some of the background on what I’m doing and why.


Thanks,
Mark
 
This is how you use the EVAL statement with arguments:
Eval(YourFunctionName("arg1;arg2;arg3")
 
OOPs! Forgot the right parenthesis
Eval(MMC_RevisonFileCopy("arg1;arg2;arg3"))
 
Thanks,

So, taking my first example I should code it:
Private Sub Command0_Click()


Eval ("MsgBox(""msg"";;""title"")")

Do I have that right? I'll try it.

Thanks.
Mark
 
Hi,


Using the Semicolon in place of the comma doesn't work. However, I disovered that if I put in the missing parameter, I can get it to work.

Eval ("MsgBox(""msg"",0,""title"")")
' works if I put in the zero.


Thanks,

Mark

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top