Solved

Validate for duplicate values during data entry

Posted on 2004-08-20
6
223 Views
Last Modified: 2012-05-05
frmAddMedication allows a user to select  a med, enter dosage, date, dr. Before the record is saved I want to check to ensure that resident is not already on that med.  This form is bound to tblResidentMedication.  Investigating the before update event looks great however, I am just not sure how to code.
0
Comment
Question by:JamieRhodes
6 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 11854969
What is resident? and which field on the table you want it check for existence?
0
 
LVL 16

Accepted Solution

by:
Nestorio earned 250 total points
ID: 11855447
Try this:

Private Sub Resident_BeforeUpdate(Cancel As Integer)
RecordsetClone.FindFirst "Resident = '" & Me.Resident & "'"
If Not RecordsetClone.NoMatch Then
MsgBox "Duplicate Key. Please reenter"
Cancel = -1
End If
End Sub


Assuming Resident is the field name which no allow duplicates.
0
 
LVL 9

Expert Comment

by:solution46
ID: 11858436
Jamie,

sounds like you're talking about patients resident at a hospital or similar? If so, then presumably you have some way of tracking patient 'visits' or 'episodes' or whatever terminology your place uses. If you have a unique way of identifying each visit, rather than each patient, you could try setting a primary key (or other unique index) across the fields MedicationID and VisitID. Just thought, if there is some reason why the patient would only ever visit once, then you can make the index unique across the fields PatientID and MedicationID. If you could have multiple visit from the same patient, but no way of identifying them, you are going to have difficulty detecting when a duplicate PatientID / MedicationID is genuine (in some cases it may be historical and not relevant to the current visit).

With the unique index in place, the system will fail every time you try to enter a duplicate VisitID / MedicationID; the error message is not particularly user-friendly but this at least a simple solution.


s46.
0
 

Author Comment

by:JamieRhodes
ID: 12607533
solution46

I am not needing to track visits, just the meds the patient is on.


capricorn1

Resident/patient is the person. the table that the info is going into is tblResidentMedications

Nestorio

I will try it .
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Running sum query 6 33
DBF to ... Converter 5 45
access 7 26
how to stop the insert of a new record under testing conditions 5 10
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now