<p>I'm trying to do a domain lookup in vba with something like this:</p>

<pre><code>DLookup("island", "villages", "village = '" &amp; txtVillage &amp; "'")
</code></pre>

<p>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.</p>

<p>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?</p>

It's worse than you think.  Think about what would happen if someone entered a value like this, and you haven't escaped anything:
```
```
'); DROP TABLE [YourTable]
```
```
Not pretty.
The reason there's no built in function to simply escape an apostrophe is because the correct way to handle this is to use query parameters.  For an Ole/Access style query you'd set this as your query string:
```
```
DLookup("island", "village", "village = ? ")
```
```
And then set the parameter separately.  I don't know how you go about setting the parameter value from vba, though.