Solved

update query variable with apostrope

Posted on 2016-10-16
7
29 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
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 49

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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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 - Access MVP) 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now