I have a mailing list that I use to print mailing lables with. The trouble I
am having is duplicate entries of the names and addresses. This database is
split, address.mdb and address_be.mdb. Most all the data entry is done
though a form in address.mdb.
Is there a way to get Accress to test for the first and last names dup
before allowing the dup to be saved? Or just even to check for a name?
Sure; you do need to just *check* not prohibit - names are not unique!
I used to work with Dr. Lawrence David Wise and his colleague, Dr.
Lawrence David Wise.
I'd suggest just a little bit of VBA code in the data entry form's
BeforeUpdate event: something like
Private Sub Form_BeforeUpdate(Cancel as Integer)
Dim rs As DAO.Recordset
Dim iAns As Integer
Set rs = Me.RecordsetClone ' get the form's recordsource
rs.FindFirst "[Lastname] = " & Chr(34) & Me!txtLastName & Chr(34) _
& " AND [FirstName] = " & Chr(34) & Me!txtFirstName & Chr(34) _
& " AND [ID] <> " & Me!txtID
' using your own field and control names of course; ID is the
' Primary Key field, just want to be sure the code doesn't find
' the same record you're checking for duplicates as a duplicate!
If Not rs.NoMatch Then ' if there is a match
iAns = MsgBox("Duplicate name found! Click Yes to add anyway," _
& vbCrLf & "No to cancel this record and open the found one," _
& vbCrLf & "Cancel to cancel this entry and start over", _
vbYesNoCancel
Select Case iAns
Case vbYes
' do nothing
Case vbNo
Cancel = True
Me.Undo ' erase the current record
Me.Bookmark = rs.Bookmark ' go to the found one
Case vbCancel
Cancel = True
Me.Undo
End Select
End If
End Sub