In the Before Update event for your form, check the value of the function:
[vba]
Sub Form_BeforeUpdate(Cancel As Integer)
If Check_Duplicates() = True Then
Cancel = True
Else
' ....
End If
End Sub
[/VBA]
[VBA]
Function Check_Duplicates() As Boolean
Dim tempset As Recordset
Dim resultset As Recordset
Dim filterstring As String
Set tempset = CodeContextObject.Recordset
tempset.MoveLast
For Each Field In tempset.Fields
If Field.OrdinalPosition = 0 Then 'Primary Key
filterstring = Field.Name & "<>" & tempset(Field.OrdinalPosition).Value
Else
Select Case VarType(tempset(Field.OrdinalPosition))
Case 1, 9, 8209 '8209 is OLE
'Skip
Case 3, 6, 11
'As it is
If filterstring = "" Then
filterstring = Field.Name & "=" & tempset(Field.OrdinalPosition).Value
Else
filterstring = filterstring & " AND " & Field.Name & "=" _
& tempset(Field.OrdinalPosition).Value
End If
Case 7
'Add #
If filterstring = "" Then
filterstring = Field.Name & "=#" & tempset(Field.OrdinalPosition).Value & "#"
Else
filterstring = filterstring & " AND " & Field.Name & "=#" _
& tempset(Field.OrdinalPosition).Value & "#"
End If
Case 8
'Add quotes
If filterstring = "" Then
filterstring = Field.Name & "='" & tempset(Field.OrdinalPosition).Value & "'"
Else
filterstring = filterstring & " AND " & Field.Name & "='" _
& tempset(Field.OrdinalPosition).Value & "'"
End If
End Select
End If
Next Field
tempset.Filter = filterstring
Set resultset = tempset.OpenRecordset()
If Not (resultset.BOF And resultset.EOF) Then
Check_Duplicates = True
End If
End Function
[/vba]