Solved

Validate for duplicate values during data entry

Posted on 2004-08-20
6
209 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

771 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

12 Experts available now in Live!

Get 1:1 Help Now