473,667 Members | 2,568 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 programmaticall y as there are likely to be others in the corporate staff table.
Feb 5 '10 #1
5 2521
NeoPa
32,568 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,568 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,568 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
1941
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 Data: strsubject = " " & GetFormData("strsubject") & " " incident = " " & GetFormData("incident") & " "
1
3022
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 databases that we also support. Much help appreciated.
2
1492
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 = '" & cfName.Trim & "' Where id = " & lnID the command works fine unless and until clname and/or cfname contains an apostrophe, ie: O'Hare When the executeNonquery is run, the quotes are out of balance and a syntax error is thrown.
3
2765
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 sending the email. My code is very simple. I can't understand why the apostrophes are put there but the addresses won't work until they are stipped of the apostrophes. Here's my code: Private Sub cmdEmail_Click() If len(txtEmail) > 0 Then
5
4907
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. Almost all of the insertions and deletions were done as DoCMD.RunSQL strSQL. Our current problem: All of our prototyping for the business tool was done in with
4
1657
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 with subject "Apostrophys in text field - SQL Server as backend" and now I'm trying to figure out how to make it work in my case, particularly the input from William Ryan. What I have are a couple fields to be inserted directly as a new row, and...
4
5602
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 = '" & request.form(strSerialNum) & "', " sql01 = sql01 & "Description = '" & request.form(strDesc) & "', " sql01 = sql01 & "Location = '" & request.form(strLoc) & "', "
7
10534
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 will correctly escape the single quotes. The problem happens when I am trying to retrieve data from the database, PHP will try to comment out what it has already commented out, instead of stripping the extra single quote. So as an example, if...
8
1527
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 (apostrophes) are giving me problems. What can I do about this?
4
18497
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 $variable = "that string" ). What I am trying to figure is how to handle a string which contains both apostrophes and quotations already. Is there a something like CDATA is for XML?
0
8457
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8365
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8883
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8788
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8646
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6203
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2776
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 we have to send another system
2
2013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1778
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.