Hello all,
I want to prevent the entry of duplicate records.Actually I am using a data entry form to enter new data into one of the tables.
How can we prevent entry of duplicate records? Duplicacy shall be checked on the first two fields only.?
Please help.
If you apply a multifield index set to No Duplicates this will give you what you want. There are other ways
Can u please tell me some more. I am trying to prevent duplicate entries on a combination of two fields, eg, HQ_File_Ref & HQ_File_Date. I am using the following code in the event before update in the field HQ_File_Date
Private Sub HQ_File_Date_BeforeUpdate(Cancel As Integer)
IThis doesn’t work out. Please helpCode:f DCount("[HQ_File_Ref]", "tblPropMain", "[HQ_File_Ref] =" & Me.[HQ_File_Ref] & " AND [HQ_File_Date] = " & Me.[HQ_File_Date]) > 0 Then 'Undo duplicate entry Me.Undo 'Message box warning of duplication MsgBox "HQ File reference no...." _ & HQREF & " has already been entered." _ & vbCr & vbCr & "Click OK to revert back....", vbInformation _ , "Duplicate Information" End If End Sub
Use this code.This code basically prevents database from the duplicate records.Try this code:
Code:Dim SID As String Dim stLinkCriteria As String Dim rsc As DAO.Recordset Set rsc = Me.RecordsetClone SID = Me.strStudentNumber.Value stLinkCriteria = "[strStudentNumber]=" & "'" & SID & "'" 'Check StudentDetails table for duplicate StudentNumber If DCount("strStudentNumber", "tblStudentDetails", _ stLinkCriteria) > 0 Then 'Undo duplicate entry Me.Undo 'Message box warning of duplication MsgBox "Warning Student Number " _ & SID & " has already been entered." _ & vbCr & vbCr & "You will now been taken to the record.", _ vbInformation, "Duplicate Information" 'Go to record of original Student Number rsc.FindFirst stLinkCriteria Me.Bookmark = rsc.Bookmark End If Set rsc = Nothing End Sub
ExlGuru
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks