473,396 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

apostrophe in field value gives code error

Hi, currently i'm using the code below to select a record in a form by using a drop down box. However, when there is an apostrophe ( ' ) in the value of the selected record i get an error code. So for example: Burger King would work perfectly, but McDonald's would give me an error...


How do i get around this? Thanks!


Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo41_AfterUpdate()
  2.     ' Find the record that matches the control.
  3.     Dim rs As Object
  4.  
  5.     Set rs = Me.Recordset.Clone
  6.     rs.FindFirst "[Co Name] = '" & Me![Combo41] & "'"
  7.     If Not rs.EOF Then Me.Bookmark = rs.Bookmark
  8.  
  9.  
  10. End Sub
Mar 29 '07 #1
3 2132
Rabbit
12,516 Expert Mod 8TB
Hi, currently i'm using the code below to select a record in a form by using a drop down box. However, when there is an apostrophe ( ' ) in the value of the selected record i get an error code. So for example: Burger King would work perfectly, but McDonald's would give me an error...


How do i get around this? Thanks!


Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo41_AfterUpdate()
  2.     ' Find the record that matches the control.
  3.     Dim rs As Object
  4.  
  5.     Set rs = Me.Recordset.Clone
  6.     rs.FindFirst "[Co Name] = '" & Me![Combo41] & "'"
  7.     If Not rs.EOF Then Me.Bookmark = rs.Bookmark
  8.  
  9.  
  10. End Sub
In your FindFirst, try using " instead of '
Expand|Select|Wrap|Line Numbers
  1. rs.FindFirst "[Co Name] = " & """" & Me![Combo41] & """"
Mar 29 '07 #2
yes this works, hehe... thanks!
Mar 30 '07 #3
Rabbit
12,516 Expert Mod 8TB
Not a problem.
Mar 30 '07 #4

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

Similar topics

2
by: Vic Spainhower | last post by:
Hello, I have in my drop-down menu company names that can have apostrophe's imbedded i.e. Vic's Coffee Shop which shows fine in the menu. However, when the user updates other fields on the form...
15
by: soup_or_power | last post by:
Hello All: I'm having a whale of a problem with the following code. When the words beginning with sugg contain an escaped single-quote (\' ==> back-slash followed by quote) the script causes an...
1
by: Joel | last post by:
I realize there are many ways to handle Apostrophes in sql statements. The problem I'm having is comparing a string with an Apostrophe entered by the operator against the field in the DB (ie Field:...
2
by: CSDunn | last post by:
Hello, I have a combo box designed to look up records in a subform based on the selection made in the combo box. The Record Source for the combo box is a SQL Server 2000 View. There is one bound...
13
by: Richard Hollenbeck | last post by:
To prevent future apostrophe bugs and errors, isn't it just simpler to forbid an apostrophe from being entered into a text field? For example, couldn't "Alice's Restaurant" be changed to "Alices...
11
by: Trevor | last post by:
Hi, I currently have the following code in a subform. If Not rstPDAddresses.EOF And Not rstPDAddresses.BOF Then With rstPDAddresses txtautoAddressID.ControlSource = "='" & Nz(!autoAddressID,...
10
by: Bhavna | last post by:
I am using a Replace function to replace single quotes with double when submitting a text field in the database i.e. Replace (q, "'", "' ' ") which works fine. When I retrieve the field from the...
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
3
by: dave k | last post by:
I often use the Control and Apostrophe keys to enter the value from the same field of the previous record in a form. I would prefer to use a mouse and the double click function. Can anyone help...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.