Groundrush
Registered User.
- Local time
- Today, 01:17
- Joined
- Apr 14, 2002
- Messages
- 1,376
Hi Guys,
Anyone know how to prevent duplicates on the combination of two fields - text & numeric?
I'm currently using the code below that warns users when the combination of two fields have already been used. (Combination of the TWO fields has to always be unique so if used again will warn the user)
Works well when both fields are numeric but fails when the JobDetails field is changed to text in the main table (tblPPMPLanner)
The field that should be a text field is called "JobDetails"
Any help would be greatly appreciated
Thanks
Anyone know how to prevent duplicates on the combination of two fields - text & numeric?
I'm currently using the code below that warns users when the combination of two fields have already been used. (Combination of the TWO fields has to always be unique so if used again will warn the user)
Works well when both fields are numeric but fails when the JobDetails field is changed to text in the main table (tblPPMPLanner)
Code:
Option Compare Database
Option Explicit
Private Function IsDuplicateRecord() As Boolean
On Error Resume Next
Dim PreviousRecordID As Long
IsDuplicateRecord = False
PreviousRecordID = 0
PreviousRecordID = DLookup("TaskID", "tblPPMPlanner", "TaskID<>" & TaskID & _
" AND BuildingID=" & cboBuildingID & " AND JobDetails=" & cboJobDetails)
If PreviousRecordID <> 0 Then
MsgBox "Duplicate record"
IsDuplicateRecord = True
End If
End Function
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsDuplicateRecord Then Cancel = 1
End Sub
The field that should be a text field is called "JobDetails"
Any help would be greatly appreciated
Thanks