473,396 Members | 2,033 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.

Searching a record with special Characters

repath
14
Hi,

I use DCount function to count the number of entries for the existing customer by name of the customer in the database table.

Table Structure like: CustRegion, CustName, OrdersPlaced.

One of the customers has a name like O'Neil
Expand|Select|Wrap|Line Numbers
  1. Me.lblOrderCount.Caption = "Total Orders Placed: " & DCount("CustName", "backUpData", "[CustRegion] = '" & Me.cmbCustRegion.Value  & "' and [CustName] = '" & Me.lstRMName.ItemData(Me.lstRMName.ListIndex) & "'")
but when searching it reads like

CustName = 'O'Neil" (Neil is being ignored and is being displayed as syntax
error.

Can you please help me in searching these names.

I appreciate any help
Jan 5 '10 #1

✓ answered by Stewart Ross

Hi. As an aside to the excellent suggestions offered by my colleagues, could I also add that using the customer's name in the way you are doing is likely to lead to erroneous counts being returned. Customer names are not in any way unique - you can and will have more than one customer in a specified region with the same surname. Also, if you are searching on a surname entered as free text (that is, not retrieved from a master customer record) you are bound to have spelling issues (e.g. variants such as O'Neil, ONeil, O Neil, O'Niel, and so on).

I would recommend that you consider what makes your customer records unique and that you count on the unique key concerned - a customer reference number or the like - and not on the non-unique surname.

If you do not have a unique key defined for your customers you may find it beneficial to review your database design. In this case you may find our insights article on database normalisation and table structures useful.

-Stewart

3 2419
ADezii
8,834 Expert 8TB
The following approach will work:
Expand|Select|Wrap|Line Numbers
  1. Dim strLastName As String
  2.  
  3. strLastName = "O'Neil"
  4.  
  5. MsgBox DCount("*", "Employees", "[LastName] = """ & strLastName & """")
Jan 5 '10 #2
NeoPa
32,556 Expert Mod 16PB
Firstly, I suggest you check out Quotes (') and Double-Quotes (") - Where and When to use them. They are often used incorrectly in Access, for reasons explained therein.

I would recommend a solution similar to :
Expand|Select|Wrap|Line Numbers
  1. Dim strWhere As String
  2.  
  3. strWhere = Replace("[CustRegion]='%R' AND [CustName]='%N'", _
  4.                    "%R", Me.cmbCustRegion)
  5. strWhere = Replace(strWhere, "%R", _
  6.                    Replace(Me.lstRMName.ItemData(Me.lstRMName.ListIndex), _
  7.                            "'", "''"))
  8. Me.lblOrderCount.Caption = "Total Orders Placed: " & _
  9.                            DCount("CustName", "backUpData", strWhere)
Jan 5 '10 #3
Stewart Ross
2,545 Expert Mod 2GB
Hi. As an aside to the excellent suggestions offered by my colleagues, could I also add that using the customer's name in the way you are doing is likely to lead to erroneous counts being returned. Customer names are not in any way unique - you can and will have more than one customer in a specified region with the same surname. Also, if you are searching on a surname entered as free text (that is, not retrieved from a master customer record) you are bound to have spelling issues (e.g. variants such as O'Neil, ONeil, O Neil, O'Niel, and so on).

I would recommend that you consider what makes your customer records unique and that you count on the unique key concerned - a customer reference number or the like - and not on the non-unique surname.

If you do not have a unique key defined for your customers you may find it beneficial to review your database design. In this case you may find our insights article on database normalisation and table structures useful.

-Stewart
Jan 5 '10 #4

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

Similar topics

3
by: Barry Olly | last post by:
Hi, I'm working on a mini content management system and need help with dealing with special characters. The input are taken from html form which are then stored into a varchar column in...
18
by: jblazi | last post by:
I should like to search certain characters in a string and when they are found, I want to replace other characters in other strings that are at the same position (for a very simply mastermind game)...
3
by: Paul H | last post by:
I have a text file that contains the following: ******************** __StartCustomerID_41 Name: Fred Smith Address: 57 Pew Road Croydon
5
by: Sakharam Phapale | last post by:
Hi All, I am using an API function, which takes file path as an input. When file path contains special characters (@,#,$,%,&,^, etc), API function gives an error as "Unable to open input file"....
1
by: sonald | last post by:
Dear All, I am working on a module that validates the provided CSV data in a text format, which must be in a predefined format. We check for the : 1. Number of fields provided in the text file,...
1
by: BlackJackal | last post by:
Alright here is the problem I have for homework. I understand most of it but I am not exactly sure what the problem is asking me to do or how to search the seperate arrays using the account number...
3
KevinADC
by: KevinADC | last post by:
Purpose The purpose of this article is to discuss the difference between characters inside a character class and outside a character class and some special characters inside a character class....
2
by: chike_oji | last post by:
Hello, I am displaying data retrieved from a database as a httpresponse in a webform. I noticed that some characters such as the comma (,), display as special characters in the web browser...
9
by: drhowarddrfine | last post by:
I don't want to use a db manager, like mysql, for such a small database but I'm finding this trickier than I thought and hope someone can provide some guidance. I have a restaurant menu with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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,...

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.