Sadie Hewgill
Registered User.
- Local time
- Today, 03:12
- Joined
- Oct 18, 2010
- Messages
- 52
I have a form where I want an error message to be displayed if there is a duplicate (considering the data in about 10 fields). I would like it to allow me to leave these fields blank though, and it can count blank fields as being identical too, or just ignore them. The thing is, I don't want to completely forbid duplicates, just make the user aware, since there may be a very similar part that will have all the same fields as another record except for the ID field. I just want a warning that a similar record exists to pop up, so the user can check if they are accidentally entering the same thing. I don't want to completely forbid it. The code I have right now doesn't work too well, and it doesn't allow for nulls (not sure how to do this) but it's a start. Any ideas? Here's my code so far:
Thanks!
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If DCount("*", "Fasteners_mm", "[RawMaterial] = " & Chr(34) & Me!Combo164 & Chr(34) & " AND [RawMaterialType] = " & Chr(34) & Me!Combo156 & Chr(34) & " AND [ThicknessDiameter] = " & Me!Combo148 & "AND [Width] = " & Me!Combo140 & " AND [Length] = " & Me!Combo132 & " AND [Colour] = " & Chr(34) & Me!Combo124 & Chr(34) & "AND [Finish] = " & Chr(34) & Me!Combo116 & Chr(34) & " AND [HeatTreat] = " & Chr(34) & Me!Combo100 & Chr(34) & " AND [ReleaseDate] = " & Chr(34) & Me!ReleaseDate & Chr(34) & " AND [Designer] = " & Chr(34) & Me!Combo62 & Chr(34)) > 0 Then
Cancel = True
If MsgBox("The record you have entered already exists, Press Ok to be taken to the existing record, or Cancel to edit this record.", vbOKCancel, "Duplicate record ") = vbOK Then
strWhere = "[RawMaterial] = " & Chr(34) & Me!Combo164 & Chr(34) & " AND [RawMaterialType] = " & Chr(34) & Me!Combo156 & Chr(34) & " AND [ThicknessDiameter] = " & Chr(34) & Me!Combo148 & Chr(34) & "AND [Width] = " & Chr(34) & Me!Combo140 & Chr(34) & " AND [Length] = " & Chr(34) & Me!Combo132 & Chr(34) & " AND [Colour] = " & Chr(34) & Me!Combo124 & Chr(34) & "AND [Finish] = " & Chr(34) & Me!Combo116 & Chr(34) & " AND [HeatTreat] = " & Chr(34) & Me!Combo100 & Chr(34) & " AND [ReleaseDate] = " & Chr(34) & Me!ReleaseDate & Chr(34) & " AND [Designer] = " & Chr(34) & Me!Combo62 & Chr(34)
Me.Undo
Set rst = Me.RecordsetClone
With rst
.FindFirst strWhere
Me.Bookmark = rst.Bookmark
.Close
End With
Response = acDataErrContinue
Else
Response = acDataErrContinue
End If
End If
End Sub
Last edited by a moderator: