Results 1 to 5 of 5
  1. #1
    graccess is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    78

    Question Preventing duplicate entries...

    I have a form where the field, [txtTicker] would be the primary method of searching within my form as well as editing a record (not to be confused with primary key). I've tried using the DLookup function to take the entered field in my form, txtTicker, and compare it to my table, [Companytable] with the respective field, [Ticker], but my syntax and design are probably both incorrect. I'm placing the code in my form within a sub procedure that is taking all my data entered and inserting it into my table. I'd like to prompt myself prior to executing the SQL code that the primary entry txtTicker already exists and if so do I wish to overwrite the data or cancel the action. It's possible I should be writing a query or two to perform these steps but I'm getting bogged down a bit. Any suggestions would be most helpful.



    'prevent dupes by checking my table and alert


    If IsNull(DLookup("[Ticker]", _
    "[Companytable]", _
    "[Ticker]='" & Me.txtTicker & "'")) Then
    MsgBox "Duplicate!"


    End If

    So, this is returning "Duplicate" only when it's an original. Not what i'm looking for naturally. I tried using NotIsNull but that had errors. Thanks in advance!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Need a space between Not and IsNull: Not IsNull(...
    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
    graccess is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    78
    Ah Thanks. Silly error.

    Another question on this. This code will be in the beginning of a subroutine which will add the inputted field information. For now, this code fires a msgbox, but I also want it to abort the add data procedure. How would you code for that?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Could test for the duplication and only continue procedure if not duplicate

    Sub something()
    If Not IsNull(...) Then
    MsgBox "Duplicate. Procedure terminated."
    Else
    'other code
    End If
    End Sub
    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.

  5. #5
    graccess is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2014
    Posts
    78
    Sweet, that worked great. thanks again for your help!

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

Similar Threads

  1. Replies: 8
    Last Post: 09-16-2013, 01:12 PM
  2. Replies: 2
    Last Post: 02-28-2013, 10:06 AM
  3. Replies: 1
    Last Post: 04-25-2012, 01:57 PM
  4. preventing duplicate records
    By Alliana Gray in forum Access
    Replies: 6
    Last Post: 08-11-2011, 01:18 PM
  5. Replies: 1
    Last Post: 02-03-2010, 08:27 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