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 - 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
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
The following approach will work: - Dim strLastName As String
-
-
strLastName = "O'Neil"
-
-
MsgBox DCount("*", "Employees", "[LastName] = """ & strLastName & """")
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 : - Dim strWhere As String
-
-
strWhere = Replace("[CustRegion]='%R' AND [CustName]='%N'", _
-
"%R", Me.cmbCustRegion)
-
strWhere = Replace(strWhere, "%R", _
-
Replace(Me.lstRMName.ItemData(Me.lstRMName.ListIndex), _
-
"'", "''"))
-
Me.lblOrderCount.Caption = "Total Orders Placed: " & _
-
DCount("CustName", "backUpData", strWhere)
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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)...
|
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
|
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"....
|
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,...
|
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...
|
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....
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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: 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,...
| |