473,407 Members | 2,676 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,407 software developers and data experts.

Help Needed With DCount

I'm using the following code to check for duplicate names when I exit
the field "MemberName" on a form:

If DCount("*", "tblMembers", "[MemberName] = '" & Me![MemberName] &
"'") <0 Then
DoCmd.CancelEvent
MsgBox "This Name is already in use." , vbExclamation, "Error"
Me![MemberName].SetFocus
End If

This works fine unless the MemberName in question contains an
apostrophe eg. O'Donnell Jim.
In this case the code is seeing the name as a duplicate. Is there a
simple way to fix this?

Nov 14 '07 #1
5 6131
On Tue, 13 Nov 2007 20:01:25 -0800, Wayne <cq*******@volcanomail.com>
wrote:

Yes. Use the Replace function to double up on the single quotes.
-Tom.
>I'm using the following code to check for duplicate names when I exit
the field "MemberName" on a form:

If DCount("*", "tblMembers", "[MemberName] = '" & Me![MemberName] &
"'") <0 Then
DoCmd.CancelEvent
MsgBox "This Name is already in use." , vbExclamation, "Error"
Me![MemberName].SetFocus
End If

This works fine unless the MemberName in question contains an
apostrophe eg. O'Donnell Jim.
In this case the code is seeing the name as a duplicate. Is there a
simple way to fix this?
Nov 14 '07 #2
On Nov 14, 2:08 pm, Tom van Stiphout <no.spam.tom7...@cox.netwrote:
On Tue, 13 Nov 2007 20:01:25 -0800, Wayne <cqdigi...@volcanomail.com>
wrote:

Yes. Use the Replace function to double up on the single quotes.
Thanks for the response Tom. I changed the single quotes to doubles,
but the code no longer picks up duplicate MemberNames.

Nov 14 '07 #3
On Tue, 13 Nov 2007 20:01:25 -0800, Wayne wrote:
I'm using the following code to check for duplicate names when I exit
the field "MemberName" on a form:

If DCount("*", "tblMembers", "[MemberName] = '" & Me![MemberName] &
"'") <0 Then
DoCmd.CancelEvent
MsgBox "This Name is already in use." , vbExclamation, "Error"
Me![MemberName].SetFocus
End If

This works fine unless the MemberName in question contains an
apostrophe eg. O'Donnell Jim.
In this case the code is seeing the name as a duplicate. Is there a
simple way to fix this?
If DCount("*", "tblMembers", "[MemberName] = """ & Me![MemberName] &
"""") <0 Then

Note: If you use the [MemberName] control's BeforeUpdate event, you
can use
Cancel = True
to cancel the entry being saved, and focus is automatically returned
to the MemberName control.

If DCount("*", "tblMembers", "[MemberName] = """ & Me![MemberName] &
"""") <0 Then
MsgBox "This Name is already in use." , vbExclamation, "Error"
Cancel = True

But what happens if there are several different Smith's who wish to
become members? Does one of them get renamed 'Jones' and the other
'Anderson'? <gI think, if you wish to assure that the same person is
not entered more than once, you need to allow the user to enter the
same name (because it's a different person).

If DCount("*", "tblMembers", "[MemberName] = """ & Me![MemberName] &
"""") <0 Then
If MsgBox("This Name is already in use." & vbNewLine & "Is this
a different person than already entered?" , vbYesNo + vbExclamation,
"Error") = vbNo Then
Cancel = True
End If
End If

If No is selected the name is not saved, otherwise it is saved.

Use the MemberID (or some other unique field) to differentiate between
members, not their name.

--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Nov 14 '07 #4
Wayne <cq*******@volcanomail.comwrote in news:1195012885.569056.40280
@v29g2000prd.googlegroups.com:
I'm using the following code to check for duplicate names when I exit
the field "MemberName" on a form:

If DCount("*", "tblMembers", "[MemberName] = '" & Me![MemberName] &
"'") <0 Then
DoCmd.CancelEvent
MsgBox "This Name is already in use." , vbExclamation, "Error"
Me![MemberName].SetFocus
End If

This works fine unless the MemberName in question contains an
apostrophe eg. O'Donnell Jim.
In this case the code is seeing the name as a duplicate. Is there a
simple way to fix this?
I would try "[MemberName] = " & Chr$(34) & Me![MemberName] & Chr$(34)

--
lyle fairfield
Nov 14 '07 #5
I would try "[MemberName] = " & Chr$(34) & Me![MemberName] & Chr$(34)

--
lyle fairfield
Cheers Lyle. Works perfectly.

Nov 14 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Classified | last post by:
Hey There, Have a problem, hopefully someone out here can lend me a hand. Working on an appointment databases, haven't used VBA in ages and I am find a lot of rust everywhere. What I'm...
7
by: jdph40 | last post by:
I posted this problem previously and received excellent help from Wayne Morgan. However, I still have an unanswered question. My form (frmVacationWeeks) is opened from the OnClick event of a...
1
by: Simon Matthews | last post by:
Hope someone can help an Access beginner! I've just started keeping my surgical logbook on access and it's a simple flat-file affair. I have created several queries that will list cases...
15
by: sara | last post by:
Hi I'm pretty new to Access here (using Access 2000), and appreciate the help and instruction. I gave myself 2.5 hours to research online and help and try to get this one, and I am not getting...
4
by: DGolfer | last post by:
I have a Tabular Form which lists my score per hole in the way of "Par" "Birdie" ect. I need to create a Text box which counts the number of times "Par" is listed or each hole. EG: Form Name is:...
3
by: Saxman | last post by:
=DCount("*","Clients"," = '1'")+DCount("*","Clients"," = '1'")+DCount("*","Clients"," = '1'")+DCount("*","Clients"," = '1'")+DCount("*","Clients"," = '1'")+DCount("*","Clients"," = '1'") The...
2
by: Kaspa | last post by:
Hello I am trying to create dcount field but is not working I have tried every way possible and I can't get it to work. here is my code: =Dcount("","qryTotalscratched"," in (6,7,8,9) and ...
2
by: David | last post by:
Dear All I'm trying to use a multi-select listbox as criteria to either add new record or edit the current record of the destiantation table with each row selected in the box. This works fine...
2
by: cephal0n | last post by:
I am in a great need of help here, I’m using union sql using access for the firs time and I'm stuck with this problem, I used a DCount to count records and create a single line of results, here is...
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
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
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...

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.