Application.Eval()不使用表达式

时间:2016-04-15 18:06:14

标签: vba ms-access access-vba

这行代码不会评估:

If(StrComp(Left("Campaign", 5), "IMS :") = 0

我这样使用它:

strHolder = "If(StrComp(Left("Campaign", 5), "IMS :") = 0"
myVar = Application.Eval(strHolder)

这是我收到的错误:

Run-time error '2425':

The expression you entered has a function name that Microsoft Access can't find.

我猜测Application.Eval无法读取IfStrCompLeft

不知道该怎么做,我无法找到有关Eval方法的详细信息。

1 个答案:

答案 0 :(得分:3)

  

这行代码不会评估:

If(StrComp(Left("Campaign", 5), "IMS :") = 0

由于括号不平衡而且它不会编译,If没有Then

此行还应该有编译错误......

strHolder = "If(StrComp(Left("Campaign", 5), "IMS :") = 0"

如果你想要这样的立即窗口示例......

? StrComp(Left("Campaign", 5), "IMS :") = 0
False

...然后将您提交给"的字符串中的Eval()字符加倍...

strHolder = "StrComp(Left(""Campaign"", 5), ""IMS :"") = 0"
? strHolder
StrComp(Left("Campaign", 5), "IMS :") = 0
myVar = Application.Eval(strHolder)
? myVar
 0
? CBool(myVar)
False