PC Review


Reply
Thread Tools Rate Thread

Apostrophe Problem

 
 
Mike
Guest
Posts: n/a
 
      28th Jun 2003
I have an application in which my users sometimes use an apostrophe in their
entries. This really causes me alot of problems in queries and reports,
because it thinks its half a quote or something. Is there a way to handle
apostrophes in data? At the moment, I have a person in the database named
O'Donnell. I can't seem to run reports about him, or anyone else with the O'
convention in their name. If I take out the apostrophe, I can't match his
name to do the reports, because obviously O'Donnell doesn't match ODonnell.
I have many more names like this. Any ideas?

Thanks
Mike


 
Reply With Quote
 
 
 
 
Wayne Morgan
Guest
Posts: n/a
 
      28th Jun 2003
You will need to use double quotes instead of single quotes to delimit the string, but how
you do that will depend on exactly what you are doing.

Here is a quick example of what needs to be done.

Public Function TestQuotes()
Dim strTextString
strTextString = "O'Hare"
TestQuotes = "SELECT [JobFile].[Name] FROM JobFile WHERE [JobFile].[Name] LIKE """ &
strTextString & """;"
End Function

In the debug window type
?TestQuotes
to get the return value what you will get back is
SELECT [JobFile].[Name] FROM JobFile WHERE [JobFile].[Name] LIKE "O'Hare";

You can also use Chr(34) concatenated in instead of the multiple double quotes. Chr(34) is
a double quote. I'm not very good at counting the double quotes, I usually just have to
play with them until I get them correct. Sometimes it takes 3 and sometimes it takes 4
(""" or """").

--
Wayne Morgan
Microsoft Access MVP


"Mike" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I have an application in which my users sometimes use an apostrophe in their
> entries. This really causes me alot of problems in queries and reports,
> because it thinks its half a quote or something. Is there a way to handle
> apostrophes in data? At the moment, I have a person in the database named
> O'Donnell. I can't seem to run reports about him, or anyone else with the O'
> convention in their name. If I take out the apostrophe, I can't match his
> name to do the reports, because obviously O'Donnell doesn't match ODonnell.
> I have many more names like this. Any ideas?
>
> Thanks
> Mike
>
>



 
Reply With Quote
 
 
 
 
Brendan Reynolds \(MVP\)
Guest
Posts: n/a
 
      28th Jun 2003
In a SQL string, you need to replace any occurrence of an apostrophe with
two apostrophes. In Access 2000 and later, the built-in Replace() function
makes this easy. Here's an example from a current project ...

Set rst = db.OpenRecordset("SELECT Count(*) AS TheCount FROM tblMessage
WHERE MessageText = '" & Replace(Me!txtMessageText, "'", "''", 1, -1,
vbBinaryCompare) & "' AND MessageID <> " & Me!MessageID)

For more information and some alternative approaches to the problem, see the
help topic 'Quotation Marks in Strings'. In Access 2000 and later, to find
this topic make sure to start your search from the VBA window, not the
Access window.

--
Brendan Reynolds (Access MVP)
(E-Mail Removed)

"Mike" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I have an application in which my users sometimes use an apostrophe in

their
> entries. This really causes me alot of problems in queries and reports,
> because it thinks its half a quote or something. Is there a way to handle
> apostrophes in data? At the moment, I have a person in the database named
> O'Donnell. I can't seem to run reports about him, or anyone else with the

O'
> convention in their name. If I take out the apostrophe, I can't match his
> name to do the reports, because obviously O'Donnell doesn't match

ODonnell.
> I have many more names like this. Any ideas?
>
> Thanks
> Mike
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Apostrophe DROITE --> Apostrophe COURBE Clarabellas Microsoft Word Document Management 3 10th Jul 2009 07:17 PM
Apostrophe Problem. Please help! =?Utf-8?B?YmFkYnJlYWtlcg==?= Microsoft Outlook Discussion 5 16th Nov 2004 11:37 PM
Apostrophe/quotation mark problem Tobby Windows XP General 0 4th Sep 2004 06:03 PM
Apostrophe's causing a problem in outgoing messages Penny Microsoft Outlook Discussion 0 13th May 2004 12:06 PM
Re: Having a problem with the apostrophe and quote key not appearing in print until i hit the next key. Word 2003 Suzanne S. Barnhill Microsoft Word Document Management 0 29th Apr 2004 11:17 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:13 AM.