Results 1 to 5 of 5
  1. #1
    arothacker is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jan 2014
    Posts
    43

    Prevent duplicate based on two criteria

    Hello-

    I have the following code to prevent duplicate entries in one of my fields:

    Private Sub txtWWID_BeforeUpdate(Cancel As Integer)
    If DCount("WWID", "Updated Headcount", "[WWID] = '" & Me.txtWWID & "'") > 0 Then
    MsgBox ("This Value Already Exists! Please Enter New Value")
    Cancel = True
    End If


    End Sub

    I need the code to lookup to see if the value exists in the WWID column AND look in the field named "Number" for a value 1. If the value exists in the WWID field AND has a 1 in the Number field then the message box pops up to prevent the entry.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Maybe:

    If Not IsNull(DLookup("[WWID]", "[Updated Headcount]", "[WWID] = '" & Me.txtWWID & "' AND [Number]=1")) Then
    Last edited by June7; 02-12-2014 at 12:22 PM.
    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
    arothacker is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jan 2014
    Posts
    43
    Hmm doesn't seem to work. I get an run error. Is there anyway to add on to the current code to add the AND statement in there?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    That's what I attempted - to expand the DLookup.

    What is the exact error message?

    I just noticed the space in "Updated Headcount", need to enclose in []. I corrected post.

    Number is a reserved word. Should avoid reserved words as names.
    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
    arothacker is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jan 2014
    Posts
    43
    I actually got it figured out. I used:

    If DCount("WWID", "Updated Headcount", "[WWID] = '" & Me.txtWWID & "' And [Number] > 0") > 0 Then

    Thanks though!

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

Similar Threads

  1. How to prevent duplicate records
    By talktime in forum Programming
    Replies: 7
    Last Post: 05-15-2013, 11:02 PM
  2. Dcount prevent duplicate
    By ayamali in forum Programming
    Replies: 20
    Last Post: 04-16-2013, 09:31 PM
  3. Replies: 19
    Last Post: 04-05-2013, 01:28 PM
  4. Prevent duplicate dates
    By bishop0071 in forum Access
    Replies: 1
    Last Post: 01-09-2013, 09:04 PM
  5. Delete Duplicate Records Based on Criteria
    By chadd in forum Queries
    Replies: 2
    Last Post: 02-07-2012, 04:24 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