由网友(人自醉)分享简介:我试图做一个域查找在VBA像这样的东西:I'm trying to do a domain lookup in vba with something like this:DLookup("island", "villages", "village = '" & txtVillage & "'")这正常工作,直到tx...
我试图做一个域查找在VBA像这样的东西:
I'm trying to do a domain lookup in vba with something like this:
DLookup("island", "villages", "village = '" & txtVillage & "'")
这正常工作,直到txtVillage是像狄龙湾,当撇号被视为一个单引号,并且我得到一个运行时错误。
This works fine until txtVillage is something like Dillon's Bay, when the apostrophe is taken to be a single quote, and I get a run-time error.
我已经写了一个简单的函数,转义单引号 - 它取代'和''。这似乎是一些出现相当频繁,但我找不到任何引用内置函数做同样的。难道我错过了什么?
I've written a trivial function that escapes single quotes - it replaces "'" with "''". This seems to be something that comes up fairly often, but I can't find any reference to a built-in function that does the same. Have I missed something?
推荐答案
替换功能应该做的伎俩。根据您的code以上:
The "Replace" function should do the trick. Based on your code above:
DLookup("island", "villages", "village = '" & Replace(txtVillage, "'", "''") & "'")
相关推荐
最新文章