Check for uniqueness of field value

D

Duck

I am putting together a database which will compile patient records
for a doctors office. I have created a form for the staff to use to
add patients to the tblPatients table. I need some sort of way for
the form to present a msgbox if a staff member attempts to enter the
same person more than once. I was thinking that I could have a msgbox
present itself is the staff member tries to enter the same combination
first and last name, or the same address as is part of an already
existing record. I mean for the msgbox to be merely a warning that
someone with that name or living at that address already exists in the
database.
 
S

Stockwell43

You could open your table to design view and click on the address field. at
the bottom where it says Indexed, select Yes, No Duplicates.
 
K

Klatuu

If husband and wife or parent and child are both patients, this would be a
problem.
Names can also be duplicates.
I would suggest a search form where the user would enter a first name, last
name, and address. The do a DLookup to look for a match. Based on the
results, either open the main form in Add mode with the fields already
entered prepopulated for new patients or in edit mode with the patient
already selected.
 
D

Duck

You could open your table to design view and click on the address field. at
the bottom where it says Indexed, select Yes, No Duplicates.





- Show quoted text -

I only want the database to warn the user if another record contains
some of the same information, for instance it is entirely possible for
two people to have the same first and last name (we have 20,000
patients), also more than one member of the same family (same address).
 
L

Larry Daugherty

Just a thought about a somewhat different approach:

Put a combobox on your form (cboFindPatient) with LimitToList enabled
and Autoexpand enabled. Base the combobox on your tblPatient with the
underlying query returning the primary key and patient last name and
patient first name and MI sorted Ascending.

The combobox Wizard will help you set it up and generate the
appropriate code for the operation you indicate. You want to go to a
particular record....

The selected record will populate the form and your users can inspect
and compare the record there with the one they know actually applies
to the current patient. If they're definitely not the same person
then add a new record.

If you were unable to find the Patient's name then continue to type
the Last Name you're looking for and click out of the combobox. That
will fire the NotInList event. You will have to write some code to
handle that but essentially, you'll put up a msgbox that will inform
your user that the name doesn't exist, would they like to add it? If
they want to add it, send the form to a new record and place the name
already entered in the Last Name field.

If the name that was not in the list is simply a typo the user will
simply indicate that they don't want to add it.

There is Access Help on the NotInList event. I've enclosed a working
example FYI. Your mileage may vary. This procedure makes use of
"fSendKeys" a safer version of the standard SendKeys provided by
Access. The code for that functionality is available at
www.mvps.ort/access It was contributed by Ken Getz.

Where the sample code opens a different form, you may wish to simply
go to a new record with the current form.

----------------------------------------------------------------------
-----------------------------------
Private Sub cboFindPractitioner_NotInList(NewData As String, Response
As Integer)
'============================================================
' Purpose: If not in list, does she want to add it?
' Copyright: Larry Daugherty
' Company: Business Process Solutions
' Programmer: Larry Daugherty
' Called From:
' Date: 11/13/02
' Parameters:
'============================================================
On Error GoTo cboFindPractitioner_NotInList_Err
Dim strErrMsg As String 'For Error Handling

Dim strMsg As String
Dim Holder As String

Holder = NewData

strMsg = "'" & NewData & "' is not listed. "
strMsg = strMsg & "Would you like to add an entry?"
If MsgBox(strMsg, vbYesNo, "Practitioner") = vbNo Then
fSendKeys "{ESC}"
Response = acDataErrContinue
Else
Response = acDataErrAdded

'Open the form to add the new one and stay there until done
DoCmd.OpenForm "frmContactPractitioner", , , , , acDialog

End If

cboFindPractitioner_NotInList_Exit:
On Error Resume Next
Exit Sub

cboFindPractitioner_NotInList_Err:
Select Case Err
Case Else
strErrMsg = strErrMsg & "Error #: " & Format$(Err.Number)
& vbCrLf
strErrMsg = strErrMsg & "Error Description: " &
Err.Description
MsgBox strErrMsg, vbInformation,
"cboFindPractitioner_NotInList"
Resume cboFindPractitioner_NotInList_Exit
End Select

End Sub
----------------------------------------------------------------------
--------------------------

HTH
--
-Larry-
--

You could open your table to design view and click on the address field. at
the bottom where it says Indexed, select Yes, No Duplicates.





- Show quoted text -

I only want the database to warn the user if another record contains
some of the same information, for instance it is entirely possible for
two people to have the same first and last name (we have 20,000
patients), also more than one member of the same family (same
address).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top