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

How to have field autosearch for duplicate entry?

I have a form setup to keep track of patients and a subform setup for their separate visits. I need to find a way so when a user inputs the number of a person who is already in the database in the main form, a message will come up to let the user know before they start entering visit data in the subform. Any ideas?
Nov 4 '10 #1

✓ answered by ADezii

It does make a difference if Patient Number is TEXT instead of NUMERIC. Notice the slight change in Code Line# 4 below:
Expand|Select|Wrap|Line Numbers
  1. Private Sub PatientNum_BeforeUpdate(Cancel As Integer)
  2. Dim intResponse As Integer
  3.  
  4. If DCount("*", "tblPatients", "[PatientNum] = '" & Me![PatientNum] & "'") > 0 Then
  5.   MsgBox "Patient [" & Me![PatientNum] & "] already exists in the Database!", vbExclamation, "Duplicate Patient"
  6.     Cancel = True
  7. End If
  8. End Sub

5 2177
ADezii
8,834 Expert 8TB
  1. ASSUMPTIONS:
    • Table Name is tblPatients.
    • tblPatients contains a Field named [PatientNum]{LONG}, which is a Numeric Value uniquely identifying a specific Patient.
    • The Field Name on your Form Bound to [PatientNum], and also named PatientNum, is used to enter Patient Numbers.
  2. The following Code, placed in the BeforeUpdate() Event of the PatientNum Field on the Form, will check for the existence of a Duplicate Patient. If this is a Duplicate Entry, the Update of the Field will be cancelled, and the User notified via a Message Box.
    Expand|Select|Wrap|Line Numbers
    1. Private Sub PatientNum_BeforeUpdate(Cancel As Integer)
    2. If DCount("*", "tblPatients", "[PatientNum] = " & Me![PatientNum]) > 0 Then
    3.   MsgBox "Patient [" & Me![PatientNum] & "] already exists in the Database!", vbExclamation, "Duplicate Patient"
    4.     Cancel = True
    5. End If
    6. End Sub
Nov 4 '10 #2
Thanks for the response!

I put the code in, but it does not do anything. I think it might be because the patient number field is a text field. This is because it has dashes is it. Will this affect the results?
Nov 4 '10 #3
ADezii
8,834 Expert 8TB
It does make a difference if Patient Number is TEXT instead of NUMERIC. Notice the slight change in Code Line# 4 below:
Expand|Select|Wrap|Line Numbers
  1. Private Sub PatientNum_BeforeUpdate(Cancel As Integer)
  2. Dim intResponse As Integer
  3.  
  4. If DCount("*", "tblPatients", "[PatientNum] = '" & Me![PatientNum] & "'") > 0 Then
  5.   MsgBox "Patient [" & Me![PatientNum] & "] already exists in the Database!", vbExclamation, "Duplicate Patient"
  6.     Cancel = True
  7. End If
  8. End Sub
Nov 4 '10 #4
IT works!! Thank you so much for your help!
Nov 4 '10 #5
ADezii
8,834 Expert 8TB
You are quite welcome.
Nov 4 '10 #6

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

Similar topics

0
by: Geetu | last post by:
I am trying to jar up a file and getting this exception, not sure what could be wrong. The same piece of code works fine in few machines but there is one machine where this piece of code gives this...
0
by: jjliu | last post by:
i have a table with two fields (id and myfield). id is a primary key not nll auto_increment, and myfield is set as unique... Due to unique setting for myfield, if i try to insert the duplicate...
0
by: Gary Lundquest | last post by:
I have an application with MS Access 2000 as the front end and MySQL as the back end. All was well until I upgraded the MySQL (Linux) server. The Problem: I insert data into a cumulative table....
1
by: Joseph Chase | last post by:
I am running version 4.1.13a-log on a Mac XServe. How can I receive a 'duplicate entry' error for an UPDATE? An update isn't creating an entry, so why this error message? ...
8
by: Iona | last post by:
Hi Allan, I'm using a nifty piece of code you put on here some time back to do a duplicate entry check as below. I'm using to check for duplicate names. However I am getting an error message on...
3
emandel
by: emandel | last post by:
In my DB I have an Events Table, a Participants table, and a attendance table. The attendance table is the junction table that connects the other two (many to many). So in the attendance tale, I...
5
by: baur79 | last post by:
Hi guys i try to run this code in loop and to pass even the entry is duplicated def email_insert_in_db(email): sql="INSERT INTO emails (email) values ('%s') "%(email)...
3
by: patelxxx | last post by:
I'm trying to update a template on our Content Management System, however getting the following error. I know its difficult to know what the problem is without looking at the PERL coding, however...
1
by: chicago1985 | last post by:
I have a unique constraint in my Oracle table for 3 fields. If I enter duplicate info on the table using Oracle client I will get an Ora message error ORA-00001 that tells me it is a duplicate entry...
36
by: ashenton | last post by:
Hi, I have a stock database and have recently solved an issue with duplication. When a user enters a duplicate value in the 'DAMS_Number' field on a form, a message box alerts the user that the...
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...
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...
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
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,...
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.