473,480 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

To Search for a Record by a field and see if there is duplicate name

18 New Member
Sorry for the title did not know what to call this.

I have 1 "All" table with the following field names

ID --> Autonumber and Primary Key
Firstname --> Text
Surname --> Text
Doctor --> Text
Diagnosis --> Text
Notes --> Text
DOB --> Date/Time

I have a form "New" to add new patients to the data base
I would like the DOB to find any duplicated data.

which i have working with this code
Expand|Select|Wrap|Line Numbers
  1. If Nz(DLookup("[DOB]", "ALL", "[DOB]"), Me.DOB) <> Me.DOB Then GoTo NO Else GoTo YES
That works great but i would like to, if a duplicate is found to
see if DOB "duplicate" has the same FirstName
and Surname and then warn the user that the patient already
exist but if it doesn`t the carry on.

Thank you in advanced sorry for carrying on :-)
Feb 2 '07 #1
6 1615
NeoPa
32,556 Recognized Expert Moderator MVP
Try this code instead of yours :
Expand|Select|Wrap|Line Numbers
  1. Dim strWhere As String
  2. strWhere = "(([DOB]=" & Format(Me!DOB,"\#m/d/yyyy\#") & ") AND " & _
  3.            "([Firstname]=' & Me!Firstname & "') AND " & _
  4.            "([Surname]=' & Me!Surname & "'))"
  5. If IsNull(DLookup("[DOB]", "ALL", strWhere)) Then
  6.     'All good - continue
  7. Else
  8.     Call MsgBox("Clash found etc...")
  9.     'Don't process record
  10. End If
BTW Your question was actually quite understandable and the title was quite clear too.
Feb 2 '07 #2
powelly
18 New Member
Thank you

I had to change code slightly it`s now
Expand|Select|Wrap|Line Numbers
  1. Private Sub DOB_BeforeUpdate(Cancel As Integer)
  2.  
  3. Dim strWhere As String
  4. strWhere = "([DOB]=" & Format(Me!DOB, "\#m/d/yyyy\#") & ") AND " & _
  5.            "([Firstname]=" & Me!FirstName & ") AND " & _
  6.            "([Surname]=" & Me!Surname & ")"
  7. If IsNull(DLookup("[DOB]", "ALL", strWhere)) Then
  8.     'All good - continue
  9. Else
  10.     Call MsgBox("Clash found etc...")
  11.     'Don't process record
  12. End If
I keep getting error

Run-time error '64479':

The expression you entered as a query parameter produced this error:'The object doesn`t contain the automation object 'test."

I`m using access 97 if that makes any different
Feb 4 '07 #3
NeoPa
32,556 Recognized Expert Moderator MVP
I'm afraid your changes (to my buggy code :() were not quite right.
I'm not sure why you got the message you did get but let's start off with some properly fixed code and see where that gets us. BTW Now I know you're using this in a BeforeUpdate event procedure, I can fill it out a bit more too.
Expand|Select|Wrap|Line Numbers
  1. Private Sub DOB_BeforeUpdate(Cancel As Integer)
  2.     Dim strWhere As String
  3.  
  4.     strWhere = "(([DOB]=" & Format(Me!DOB,"\#m/d/yyyy\#") & ") AND " & _
  5.                "([Firstname]='" & Me!Firstname & "') AND " & _
  6.                "([Surname]='" & Me!Surname & "'))"
  7.     If Not IsNull(DLookup("[DOB]", "ALL", strWhere)) Then
  8.         Call MsgBox("Clash found etc...")
  9.         Cancel = True
  10.     End If
  11. End Sub
Try this out.
Feb 4 '07 #4
powelly
18 New Member
Sorry about that access was giving me errors in vb with " and () in places don`t know why but when i used this code
Expand|Select|Wrap|Line Numbers
  1. Private Sub DOB_BeforeUpdate(Cancel As Integer)
  2.     Dim strWhere As String
  3.  
  4.     strWhere = "(([DOB]=" & Format(Me!DOB,"\#m/d/yyyy\#") & ") AND " & _
  5.                "([Firstname]='" & Me!Firstname & "') AND " & _
  6.                "([Surname]='" & Me!Surname & "'))"
  7.     If Not IsNull(DLookup("[DOB]", "ALL", strWhere)) Then
  8.         Call MsgBox("Clash found etc...")
  9.         Cancel = True
  10.     End If
  11. End Sub
It worked BEAUTIFULY Just as i wanted it to.

So :-) Thank you NeoPa again very much you have helped me with other Problems before as well.

Me so HAPPY :-) :-) :-) :-) :-) :-) :-)

Cheers ROB
Feb 5 '07 #5
NeoPa
32,556 Recognized Expert Moderator MVP
I'm sorry to say that my original code was posted with some critical quotes missing :embarrassed:
I'm pleased it's working for you now :)
Feb 5 '07 #6
powelly
18 New Member
Thats ok every one has there day.THANK YOU again
Feb 5 '07 #7

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

Similar topics

1
1594
by: damjanu | last post by:
Dear All; I have 3 issues 1) On some of my tables I have unique indexes, so that for example no two phone numbers can be the same. When user enters phone number that already exists, a scary...
10
3040
by: Mark | last post by:
I have a table about people containing 25 fields. The table contains the usual fields - first, last, address, city, state and zip. There is no primary key. These fields all have data with the...
8
3193
by: Steph | last post by:
Hi. I'm very new to MS Access and have been presented with an Access database of contacts by my employer. I am trying to redesign the main form of the database so that a button entitled...
19
3441
by: davidgordon | last post by:
Hi, I need some pointers/help on how to do the following if it possible: In my access db, I have the following: Tables: Products, Sub-Assembly, Product-Pack Table, Products
1
2706
by: Eric | last post by:
Hi: I have two files. I search pattern ":" from emails text file and save email contents into a database. Another search pattern " field is blank. Please try again.", vbExclamation + vbOKOnly...
0
7037
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
6904
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
7032
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,...
1
6730
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...
1
4767
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...
0
4471
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2990
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1294
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 ...
1
558
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.