Results 1 to 4 of 4
  1. #1
    Ed Mattison is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Sep 2015
    Posts
    7

    Avoiding duplicate records without using primary key

    I have a modest sized data base and have been having trouble keeping out duplicate records with the same last name, first name, and DOB. I know I could use all 3 fields as a primary key, but I would like a simpler way of checking for duplicates. Is there such? Thanks. ed

  2. #2
    LaughingBull is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Location
    Toledo Ohio
    Posts
    143
    create a query watch this youtube https://www.youtube.com/watch?v=amRbEhQWH78

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  4. #4
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    Try this code :

    Code:
    Dim strSQL As String
    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset
    Set dbs = CurrentDb
    
    
    strSQL = "SELECT * FROM tblPersons" & _
    " WHERE FirstName = '" & Me!ctrlFirstName & _
    "' AND LastName = '" & Me!ctrlLastName & _
    "' AND DateOfBirth = '" & Me!ctrlDateOfBirth & "
    
    
    Set rst = dbs.OpenRecordset(strSQL, dbOpenDynaset)
    If Not rst.EOF Then
    If MsgBox("Person " & Me!ctrlFirstName & " and " _
    & vbCrLf & "with " & Me!ctrlLastName & "" _
    & vbCrLf & "and date of birth  " & Me!ctrlDateOfBirth & " allready exists" _
    & vbCrLf & "Click NO to cancel", _
    vbCritical + vbYesNo + vbDefaultButton2) = vbNo Then
    Me.Undo
    Exit Sub
    End If
    End If
    
    'If no match, code to create your new record below.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Avoiding duplicate rows in a report
    By deshamilton in forum Reports
    Replies: 1
    Last Post: 08-16-2014, 10:07 AM
  2. Table allowing duplicate primary keys
    By Count Duckula in forum Access
    Replies: 4
    Last Post: 06-13-2013, 09:12 AM
  3. Avoiding entering duplicate values
    By djclntn in forum Forms
    Replies: 1
    Last Post: 01-25-2013, 11:51 AM
  4. Replies: 4
    Last Post: 04-19-2012, 11:01 AM
  5. Replies: 37
    Last Post: 08-10-2011, 09:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums