A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

apostrophe in form



 
 
Thread Tools Display Modes
  #1  
Old April 22nd, 2010, 08:13 PM posted to microsoft.public.access
pkeegs
external usenet poster
 
Posts: 59
Default apostrophe in form

I have been trying to make sense of some of the previous answers in the forum
without success, so here is my problem.
My database has a client form from which I can select another form for
additional information if required. When I click on the button to select the
additional information for a person with an apostrophe in the name I get the
following message.

Syntax error (missing operator) in query expression '[Full Name]='John
O'Neill''.

The system generated code is

stLinkCriteria = "[Full Name]=" & "'" & Me![ParameterFullName] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

What do I have to do to get the code working with names containing an
apostrophe?

Cheers




  #2  
Old April 22nd, 2010, 08:24 PM posted to microsoft.public.access
Beetle
external usenet poster
 
Posts: 1,254
Default apostrophe in form

You need to replace each of those single quotes in your code
with two double quotes. So if we expand that line a bit so we
can clearly see the single quotes it would look like;

stLinkCriteria = "[Full Name]=" & " ' " & Me![ParameterFullName] & " ' "

then we replace each of those single quotes with, again, two
double quotes and we have;

stLinkCriteria = "[Full Name]=" & " "" " & Me![ParameterFullName] & " "" "

which, in your actual code will look like;

stLinkCriteria = "[Full Name]=" & """" & Me![ParameterFullName] & """"

--
_________

Sean Bailey


"pkeegs" wrote:

I have been trying to make sense of some of the previous answers in the forum
without success, so here is my problem.
My database has a client form from which I can select another form for
additional information if required. When I click on the button to select the
additional information for a person with an apostrophe in the name I get the
following message.

Syntax error (missing operator) in query expression '[Full Name]='John
O'Neill''.

The system generated code is

stLinkCriteria = "[Full Name]=" & "'" & Me![ParameterFullName] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

What do I have to do to get the code working with names containing an
apostrophe?

Cheers




  #3  
Old April 22nd, 2010, 08:25 PM posted to microsoft.public.access
pkeegs
external usenet poster
 
Posts: 59
Default apostrophe in form

I managed to work out the replace code from Douglas J Steele's posting
12/3/2005 so my code is now

stLinkCriteria = "[Full Name]=" & "'" & Replace(Me![ParameterFullName],
"'", "''") & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

and appears to be working well

"pkeegs" wrote:

I have been trying to make sense of some of the previous answers in the forum
without success, so here is my problem.
My database has a client form from which I can select another form for
additional information if required. When I click on the button to select the
additional information for a person with an apostrophe in the name I get the
following message.

Syntax error (missing operator) in query expression '[Full Name]='John
O'Neill''.

The system generated code is

stLinkCriteria = "[Full Name]=" & "'" & Me![ParameterFullName] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

What do I have to do to get the code working with names containing an
apostrophe?

Cheers




  #4  
Old April 26th, 2010, 04:44 AM posted to microsoft.public.access
pkeegs
external usenet poster
 
Posts: 59
Default apostrophe in form

Thanks Sean, much simpler than the replace option I came up with.

"Beetle" wrote:

You need to replace each of those single quotes in your code
with two double quotes. So if we expand that line a bit so we
can clearly see the single quotes it would look like;

stLinkCriteria = "[Full Name]=" & " ' " & Me![ParameterFullName] & " ' "

then we replace each of those single quotes with, again, two
double quotes and we have;

stLinkCriteria = "[Full Name]=" & " "" " & Me![ParameterFullName] & " "" "

which, in your actual code will look like;

stLinkCriteria = "[Full Name]=" & """" & Me![ParameterFullName] & """"

--
_________

Sean Bailey


"pkeegs" wrote:

I have been trying to make sense of some of the previous answers in the forum
without success, so here is my problem.
My database has a client form from which I can select another form for
additional information if required. When I click on the button to select the
additional information for a person with an apostrophe in the name I get the
following message.

Syntax error (missing operator) in query expression '[Full Name]='John
O'Neill''.

The system generated code is

stLinkCriteria = "[Full Name]=" & "'" & Me![ParameterFullName] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

What do I have to do to get the code working with names containing an
apostrophe?

Cheers




 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:34 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.