apostrophie in field value causes problems

R

RonM

I have a command button that runs fine as long as there is
not an apostrophie in the field value for [Location_Name].
i.e. if [Location_Name]="Joe's Grill"
I'm sure this is very simple to fix, I'm just a rookie...
Here is the code:

Private Sub Assignments_Btn_Click()
On Error GoTo Err_Assignments_Btn_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Assignments_By_Co"

stLinkCriteria = "[Location_Name]=" & "'" & Me!
[Location_Name] & "'"

DoCmd.OpenForm stDocName, , , stLinkCriteria
Thanks,
RM
 
C

Cheryl Fischer

Ron,

There are a couple of ways to get around this. Here's one, using Chr(34):

stLinkCriteria = "[Location_Name]=" & Chr(34) & Me![Location_Name] &
Chr(34)
 
R

RobFMS

Ron

You will want to change the single quote to 2 double quotes, using the
Replace() function (Access 2000 & up)

= Replace(<string to search in>, "'", "''", 1, , vbTextCompare)

HTH

--

Rob

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Need to launch your application in the appropriate version of Access?
http://www.fmsinc.com/Products/startup/index.asp

Need software tools for Access, VB, SQL or .NET?
http://www.fmsinc.com
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 
R

RonM

Thanks, that worked.
RM
P.S.
After my post I started getting email containing a worm.
Is this a problem on this forum? I'll use a fake email
from now on!

-----Original Message-----
Ron,

There are a couple of ways to get around this. Here's one, using Chr(34):

stLinkCriteria = "[Location_Name]=" & Chr(34) & Me! [Location_Name] &
Chr(34)

--
Cheryl Fischer
Law/Sys Associates
Houston, TX

RonM said:
I have a command button that runs fine as long as there is
not an apostrophie in the field value for [Location_Name].
i.e. if [Location_Name]="Joe's Grill"
I'm sure this is very simple to fix, I'm just a rookie...
Here is the code:

Private Sub Assignments_Btn_Click()
On Error GoTo Err_Assignments_Btn_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Assignments_By_Co"

stLinkCriteria = "[Location_Name]=" & "'" & Me!
[Location_Name] & "'"

DoCmd.OpenForm stDocName, , , stLinkCriteria
Thanks,
RM


.
 
C

Cheryl Fischer

After my post I started getting email containing a worm.
Is this a problem on this forum? I'll use a fake email
from now on!

Ron,

It's a problem everywhere these past couple of weeks. Spammers have
routinely harvested email addresses from a variety of internet resources,
UseNet newsgroups included. Unfortunately, this current outbreak spread
extremely quickly.

--
Cheryl Fischer
Law/Sys Associates
Houston, TX

RonM said:
Thanks, that worked.
RM
P.S.
After my post I started getting email containing a worm.
Is this a problem on this forum? I'll use a fake email
from now on!

-----Original Message-----
Ron,

There are a couple of ways to get around this. Here's one, using Chr(34):

stLinkCriteria = "[Location_Name]=" & Chr(34) & Me! [Location_Name] &
Chr(34)

--
Cheryl Fischer
Law/Sys Associates
Houston, TX

RonM said:
I have a command button that runs fine as long as there is
not an apostrophie in the field value for [Location_Name].
i.e. if [Location_Name]="Joe's Grill"
I'm sure this is very simple to fix, I'm just a rookie...
Here is the code:

Private Sub Assignments_Btn_Click()
On Error GoTo Err_Assignments_Btn_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "Assignments_By_Co"

stLinkCriteria = "[Location_Name]=" & "'" & Me!
[Location_Name] & "'"

DoCmd.OpenForm stDocName, , , stLinkCriteria
Thanks,
RM


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top