+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    02-26-2009
    Location
    India
    MS-Off Ver
    Access
    Posts
    69

    How can i Prevent entry of duplicate records

    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.

  2. #2
    Spammer
    Join Date
    02-26-2009
    Location
    India
    MS-Off Ver
    Outlook
    Posts
    98

    Re: How can i Prevent entry of duplicate records

    If you apply a multifield index set to No Duplicates this will give you what you want. There are other ways

  3. #3
    Registered User
    Join Date
    02-26-2009
    Location
    India
    MS-Off Ver
    Access
    Posts
    69

    Re: How can i Prevent entry of duplicate records

    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)

    I
    Code:
    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
    This doesn’t work out. Please help

  4. #4
    Forum Administrator
    Join Date
    03-18-2009
    Location
    India
    MS-Off Ver
    2003,2007
    Posts
    222

    Re: How can i Prevent entry of duplicate records

    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0