Solved

Validate for duplicate values during data entry

Posted on 2004-08-20
6
231 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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

778 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