Hi John and Jeff,
Thank you for your advices. I usually have PatientID which has autonumber is
a primary key. Howver, the numbers 1,2,3...... is a unique identifier . For
example,
Below are my records:
PatientID FirstName LastName Address Phone
1 Sue Tran 15250 568-8965
2. Ben Tran 25625 458-8956
3. Sue Tran 15250 568- 8965
The primary key (PatientID) isn't work very well because I am able to enter
" Sue Tran" many times in the table. That is why I made the FULLNAM is
primary key.
Names are not good primary keys, because they are not unique. I know three
people in the small town of Parma, all named Fred Brown. If Fred Brown and his
son Fred Brown both came to your clinic, would you turn one away!?
I would stick with the autonumber PatientID, and instead of uniquely indexing
the full name, put some VBA code in the Form's BeforeUpdate event to check for
duplicates. If you find a duplicate name, *warn* the user and give them the
option of opening the existing record - but also give them the option of
adding the record anyway. Here's some sample code. It assumes that you have a
Form based on the patient table with no filters or criteria.
Private Sub Form_BeforeUpdate(Cancel as Integer)
Dim strSQL As String
Dim rs As DAO.Recordset
Dim iAns As Integer
strSQL = "[FirstName] = """ & Me!FirstName & """ AND [LastName] = """ _
& Me!LastName & """"
' e.g [FirstName] = "Eileen" AND [LastName] = "O'Hara"
' The triplequotes evaluate to one doublequote character
Set rs = Me.RecordsetClone
rs.FindFirst strSQL
If Not rs.NoMatch Then ' a record was found for this name
iAns = MsgBox(Me.[FirstName] & " " & Me.[LastName] & " already exists!" _
& vbCrLf & "Go to the existing record? Click Yes to go, " _
& "No to add this as a new record, Cancel to quit:", vbYesNoCancel)
Select Case iAns
Case vbYes ' user clicked Yes
Cancel = True ' cancel what the user was about to add
Me.Bookmark = rs.Bookmark ' jump to the found record
Case vbNo ' user clicked No, do nothing - just let the update proceed
Case vbCancel ' user clicked Cancel, erase the form
Cancel = True
Me.Undo
End Select
End If
Set rs = Nothing ' clean up after yourself
End Sub