问题描述
我正在尝试在 vba 中使用以下内容进行域查找:
I'm trying to do a domain lookup in vba with something like this:
DLookup("island", "villages", "village = '" & txtVillage & "'")
这很好用,直到 txtVillage 类似于 Dillon's Bay,当撇号被视为单引号时,我收到运行时错误.
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?
推荐答案
替换"功能应该可以解决问题.根据您上面的代码:
The "Replace" function should do the trick. Based on your code above:
DLookup("island", "villages", "village = '" & Replace(txtVillage, "'", "''") & "'")
这篇关于在 Access SQL 中转义 '的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!