Results 1 to 6 of 6
  1. #1
    JulieMarie is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2013
    Posts
    12

    Duplicate data message for a data entry form

    I created a data input form to enter new contracts that are tied to two tables. The tables update after the data is saved in the form. I do not want users to enter in duplicate contract numbers. I would like to create a message to let users know if the data they entered is duplicate. I do not need to go to the duplicate record.

    My code shows everything I enter to be a duplicate, even when I know that the data I am entering is not a duplicate. How can I only get the message to appear if the data is truly a duplicate entry?
    Attached Files Attached Files

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Your field name doesn't have underscores, it has inadvisable spaces:

    Answer = DLookup("[Contract No]", "Contract", "[Contract No] = '" & Me.Contract_No & "'")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    JulieMarie is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2013
    Posts
    12
    I corrected it but it still gives me the message for contract numbers I know do not exist. If you look at the master contract log query it will show all of my contracts. So I entered C1234567 and it says its a duplicate, but I know this is not true. I only want the message to appear if it is truly a duplicate record. I also tried the below code with the same results. I don't know why it is saying every record is a duplicate.

    Private Sub Contract_No_BeforeUpdate(Cancel As Integer)
    Dim SID As String
    Dim stLinkCriteria As String
    Dim rsc As DAO.Recordset
    Set rsc = Me.RecordsetClone
    SID = Me.Contract_No.Value
    stLinkCriteria = "[Contract_No]=" & "'" & SID & "'"
    'Check Contract table for duplicate ContractNo
    If DCount("Contract_No", "Contract", stLinkCriteria) > 0 Then
    'Undo duplicate entry
    Me.Undo
    'Message box warning of duplication
    MsgBox "Warning Contract Number " _
    & SID & " has already been entered." _
    & vbCr & vbCr & "You will now been taken to the record.", vbInformation _
    , "Duplicate Information"
    End If
    Set rsc = Nothing
    End Sub

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What did you correct? Your code still has underscores. When I used the code I posted, I was able to enter new data.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    JulieMarie is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2013
    Posts
    12
    It works! In case you haven't heard it lately - YOU ARE A GENIUS!!!!
    Thank you so much for your help!

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    LOL! I've heard genius, but I've also heard dork, idiot, moron, and a few unrepeatable terms!

    Happy to help, and welcome to the site by the way!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 4
    Last Post: 01-14-2016, 02:18 PM
  2. Replies: 5
    Last Post: 08-12-2013, 12:53 AM
  3. Duplicate data entry on form level by user
    By Kananelo in forum Forms
    Replies: 1
    Last Post: 02-10-2012, 01:09 AM
  4. Error Message re: data entry of date
    By Pro-not in forum Access
    Replies: 9
    Last Post: 10-22-2010, 10:14 AM
  5. Entering duplicate data in Form
    By cotri in forum Forms
    Replies: 1
    Last Post: 01-06-2010, 11:45 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