To answer your second question - combo boxes work just like that. So rather
than a text box for the name, use a combo box and have its row source set up
to list all the names that are already in your database.
On the duplicate record issue - rather than have a button, use the Error
event of the form that you are using to intercept the error about duplicate
records, and then display the "duplicate" record when this happens (it won't
actually be a duplicate as you can no longer get duplicates!) There are
probably several ways to do this, but this one will work provided the
recordset of the form you are using includes the duplicate record. If you
have opened the form at a single record then you will need to change the
code a bit.
The sort of code you need is as shown below. This code assumes that you have
two fields (FirstName and LastName) that form the unique index, and that the
form has controls called txtFirstName and txtLastName bound to these fields.
You will need to change this to match your own field and control names, and
will probably need more fields than just thest two.
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Dim strWhere As String
Dim rst As DAO.Recordset
On Error GoTo HandleErrors
Select Case DataErr
Case 3022 'Duplicate record
If MsgBox("This record already exists. Click OK to go to the
existing record, or Cancel to change your entry", vbOKCancel, "Duplicate
record") = vbOK Then
strWhere = "FirstName ='" & Me.txtFirstName & "' AND LastName
='" & Me.LastName & "'"
Me.Undo
Set rst = Me.RecordsetClone
With rst
.FindFirst strWhere
Me.Bookmark = rst.Bookmark
.Close
End With
Response = acDataErrContinue
Else
Response = acDataErrContinue
End If
Case Else
End Select
ExitHere:
Exit Sub
HandleErrors:
Select Case Err.Number
Case Else
MsgBox Err.Description & " (" & Err.Number & ")"
End Select
Resume ExitHere