逃离“在访问SQL [英] Escaping ' in Access SQL

查看:186
本文介绍了逃离“在访问SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个域查找在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, "'", "''") & "'")

这篇关于逃离“在访问SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆