Solved

update query variable with apostrope

Posted on 2016-10-16
7
39 Views
Last Modified: 2016-10-17
access 2010 vba  sql  update statement
I'm trying to run a sql update but one of my variables may contain a apostrope.


code...
R![csg_email_address] = empEM



my_sql = "Update Step1_ADD_Parent_to_SATA_P2 SET [am_arm_racf] = '" & Uid & "', " & _
         "[AM_ARM_FName] = '" & empFN & "', " & _
         "[AM_ARM_LNAME] = '" & empLN & "', " & _
         "[csg_email_address] = '" & empEM & "' " & _
         "where [0BPARTNER] like '" & PntnChild & "*' "

CurrentDb.Execute my_sql, dbFailOnError

Open in new window




This line may contain an apostrope     "empEM" =   JAMES O'KEEFE
my UPDATE statement dies on execute.

I need to handle the apostrope.



Thanks
Fordraiders
0
Comment
Question by:fordraiders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 41846136
Change this line
 "[csg_email_address] = '" & empEM & "' " &
To
 "[csg_email_address] = '" & replace(empEM,"'","''") & "' " &
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 41846140
pls apply same logic as what was proposed by Haris for all char fields in your update query.
0
 
LVL 3

Author Comment

by:fordraiders
ID: 41846143
still getting error.

'james.O"KEEFE@XXXXX.COM'

Thnx
fordraiders
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75
ID: 41846149
my_sql = "Update Step1_ADD_Parent_to_SATA_P2 SET [am_arm_racf] = '" & Uid & "', " & _
         "[AM_ARM_FName] = '" &  Replace([empFN], Chr(39),"") & "', " & _
         "[AM_ARM_LNAME] = '" & Replace([empLN], Chr(39),"") & "', " & _
         "[csg_email_address] = '" & Replace([empEM], Chr(39),"") & "' " & _
         "where [0BPARTNER] like '" & Replace([PntnChild], Chr(39),"") & "*' "

CurrentDb.Execute my_sql, dbFailOnError
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 500 total points
ID: 41846150
OR

my_sql = "Update Step1_ADD_Parent_to_SATA_P2 SET [am_arm_racf] = '" & Uid & "', " & _
         "[AM_ARM_FName] = '" &  Replace(empFN, Chr(39),"") & "', " & _
         "[AM_ARM_LNAME] = '" & Replace(empLN, Chr(39),"") & "', " & _
         "[csg_email_address] = '" & Replace(empEM, Chr(39),"") & "' " & _
         "where [0BPARTNER] like '" & Replace(PntnChild, Chr(39),"") & "*' "
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 41846170
thanks joe, worked the best !
0
 
LVL 75
ID: 41846924
You are welcome.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question