Results 1 to 3 of 3
  1. #1
    ChrisLee is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2023
    Posts
    2

    Form Name Duplicates and apostrphe's

    Good Morning,
    Thanks for allowing me to join your community.



    The issue I have is with a piece of code that identifies duplicate entries in a name field and the takes me to the duplicated record.

    This works great until I have a name that has an apostrophe in it, would anybody be kind enough to point me in the right direction for dealing with this.
    Code:
    '*********************************'Code sample courtesy of srfreeman
    '*********************************
    
    
        Dim SID As String
        Dim stLinkCriteria As String
        Dim rsc As DAO.Recordset
    
    
        Set rsc = Me.RecordsetClone
    
    
        SID = Me.fullname.Value
        stLinkCriteria = "[fullname]=" & "'" & SID & "'"
    
    
        'Check StudentDetails table for duplicate StudentNumber
        If DCount("fullname", "tbl1Employees", _
                  stLinkCriteria) > 0 Then
            'Undo duplicate entry
            Me.Undo
            'Message box warning of duplication
            MsgBox "Warning Employee Name " _
                 & SID & " has already been used." _
                 & 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
    Any guidance would be much appreciated

    Have a good day

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Options:

    1. stLinkCriteria = "[fullname]=""" & SID & """"

    2. stLinkCriteria = "[fullname]=" & Chr(34) & SID & Chr(34)

    3. stLinkCriteria = "[fullname]='" & Replace(SID, "'", "''") & "'"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ChrisLee is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2023
    Posts
    2
    Hi June7,

    That was such a quick response, I really appreciate it.

    Option 1 works like a charm, thank you very much

    Have a good day

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

Similar Threads

  1. detecting duplicates in child form
    By Benj in forum Access
    Replies: 1
    Last Post: 07-04-2018, 03:04 PM
  2. Replies: 3
    Last Post: 01-18-2016, 01:55 PM
  3. Check of duplicates by name in a form
    By quicova in forum Access
    Replies: 2
    Last Post: 11-08-2013, 08:08 AM
  4. Duplicates in a form but not the query
    By tcheck in forum Access
    Replies: 4
    Last Post: 04-09-2013, 11:12 AM
  5. Hide Duplicates In Look Up Form
    By PonderingAccess in forum Queries
    Replies: 2
    Last Post: 09-30-2010, 12:23 PM

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