473,508 Members | 4,712 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I deal with single apostrophes

2 New Member
I have inherited some code that has worked well until an Irish member joined us.

His name "O'Riordan" has caused problems

Part of our basic code looks like this
Expand|Select|Wrap|Line Numbers
  1. Public Sub Check_name()
  2.  
  3. fieldmanager = Name
  4. manager = "O'Riordan Patrick"
  5. filterReport = "qry_staff"
  6.  
  7. Set rstManager = DBEngine(0)(0).OpenRecordset("SELECT distinct name FROM " _
  8.                 & filterReport & " where name = " & "'" & manager & "'")
  9.  
  10.   records = rstManager.RecordCount
  11.   MsgBox ("No of records is " & records)
  12.   rstManager.MoveFirst
  13.   manager_name = rstManager.Fields("name")
  14.  
  15.   MsgBox ("Name is " & manager_name)
  16.  
  17.  
  18. End Sub
but the query fails because his name has the single apostrophe.

Can anyone advise how I correct this programmatically as there are likely to be others in the corporate staff table.
Feb 5 '10 #1
5 2512
NeoPa
32,557 Recognized Expert Moderator MVP
You should find the code in SQL Injection Attack to be helpful here.

Further info can be found at Quotes (') and Double-Quotes (") - Where and When to use them.
Feb 5 '10 #2
NeoPa
32,557 Recognized Expert Moderator MVP
Sorry.

I just reread the first article and the code I expected (which simply doubles up all instances of these characters) doesn't appear to be there.

Your solution is as simple as that though. Does that help?
Feb 5 '10 #3
missinglinq
3,532 Recognized Expert Specialist
Also you appear to have a field called Name! Name is a Reserved Word in Access, and sooner or later this is going jump up and bite you in the rump! You really need to change it to something else.

Welcome to Bytes!

Linq ;0)>
Feb 5 '10 #4
PeterG
2 New Member
Thanks for the references. It's pointing me in the right direction so I'll spend today playing with it.

As a newbie to Access vba it is helpful having this resource
Feb 5 '10 #5
NeoPa
32,557 Recognized Expert Moderator MVP
We're always happy to help those who are willing to learn :)

Welcome to Bytes!
Feb 5 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1934
by: Lord Merlin | last post by:
When I insert info into a DB from a form, it cuts the string off at the first apostrophe ("). How would I make it insert the data as-is, with the apostrophes? Here is the code used to insert the...
1
3006
by: kalbee | last post by:
When we insert text into field in a table, SQL SERVER apparently replaces apostrophes with question marks -- is there a way to not have this occur? We don't have this happen with the mySQL...
2
1462
by: David Bird | last post by:
I am attempting to build a command string to update a field in a dataset. the command string looks like this: Dim cmdString As String = "Update set lName = '" & clName.Trim & "', fName = '" &...
3
2759
by: Richard Hollenbeck | last post by:
I have an email field and a command button to send email. The problem is that when the email program opens up there are apostrophes around the email address that I have to manually remove before...
5
4893
by: james.igoe | last post by:
History: Took over development of Access project after half of app was developed. Continued the second half using same coding style as first developer, but improved upon code and flow, etc. ...
4
1647
by: Nathan | last post by:
Hi, I'm doing a database app using MS Access and OleDb adapters, and I'm having trouble with getting strings containing apostrophes in and out of the database. I read through a thread below...
4
5594
by: Jack | last post by:
Hi, I have a asp page where part of the code is as follows. This builds up the sql statement partially. sql01 = "UPDATE EquipmentTbl SET " sql01 = sql01 & "SerialNumber = '" &...
7
10528
by: nick.bonadies | last post by:
I'm trying to deal with user inputs of single quotes into form fields that get input into a MSSQL database. So far I have discovered that if I turn on magic_quotes_sybase in my php.ini file PHP...
8
1522
by: charlespb69 | last post by:
I am new to php so this might be a real simple question. I have a form that users are able to input information into and the information goes into a mysql database table.. But single quotes...
4
18484
by: Lucanos | last post by:
Hey Guys, Probably a simple question, but one I am struggling with all the same. I know that in PHP you wrap a text string in apostrophes or quotations - (examples $variable = 'this string' OR...
0
7228
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7332
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7393
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5635
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1565
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.