Results 1 to 5 of 5
  1. #1
    TimMoffy is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    May 2012
    Posts
    29

    Question Finding Duplicate Values

    not sure if this should be under forms or queries.

    I have a form where users enter a reference number into a textbox on a form and I want to check that the ref. number does not already exist. If it does then I would like to display a form with the message on it, telling them of the duplication – can display the form easily enough.

    I have created a find duplicates query but that doesn’t really work as the reference number is not written away at that time and it also returns ALL duplicates it finds, not just for the number in the text box.



    Whenever I run the query as well it shows to the user, which isn’t very elegant and I’d like to remain hidden. I would guess this means putting into a form, which is fine, and only displaying the form if the number of records returned is greater than zero, but how to trigger the query / form ever being dsplayed. normally I would do this sort of thing using an On Click command, but do not have such a thing here so would it be on After update in the reference number text box?

    In all I’m totally stumped by this

    So what I’m asking I guess is:
    How to write the data away from the text box before the form data is saved so I can run the find duplicates query and limit that query criteria to the reference number text box. From looking at the query created by the wizard I think I need to save the data first?

    How to query the data without it being visible to the user if there is nothing to show?

    If there is data to display then I know how to run the form….. I think.

    Hope this all makes sense

    Thanks in advance for your help.

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    This is usually done using the DCount() function rather than a full blown Query. The exact syntax depends on the Datatype of the Field being used.
    Replacing Field1 with the actual name of your Field/Control, and Domain with the name of the Table or Query that holds the Field:

    If Field1 is Text

    Code:
    Private Sub Field1_BeforeUpdate(Cancel As Integer)
    If DCount("Field1", "Domain", "[Field1] = '" & Me.Field1 & "'") > 0 Then
     Resp = MsgBox("This Value Already Exists! Do You Wish to Add Anyway?", vbYesNo)
     If Resp = vbNo Then
      Cancel = True
     End If
    End If
    End Sub
    0f Field1 is Numeric

    Code:
    Private Sub Field1_BeforeUpdate(Cancel As Integer)
    If DCount("Field1", "Domain", "Field1 = " & Me.Field1) > 0 Then
     Resp = MsgBox("This Value Already Exists! Do You Wish to Add Anyway?", vbYesNo)
     If Resp = vbNo Then
      Cancel = True
     End If
    End If
    End Sub
    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    TimMoffy is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    May 2012
    Posts
    29
    Fantastic - worked first time many many thanks for your help - boss is well impressed!

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Glad we could help!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    squatter is offline Novice
    Windows XP Access 2007
    Join Date
    May 2012
    Posts
    2
    it really amazing... thanks master...

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

Similar Threads

  1. Replies: 4
    Last Post: 03-29-2012, 07:06 PM
  2. ummmm... finding duplicate rows
    By mcchung52 in forum Queries
    Replies: 3
    Last Post: 02-07-2012, 03:02 AM
  3. duplicate lookup values
    By andy33 in forum Database Design
    Replies: 2
    Last Post: 11-18-2011, 03:07 PM
  4. duplicate values
    By tarhim47 in forum Access
    Replies: 7
    Last Post: 05-03-2011, 11:30 AM
  5. Duplicate Values in table
    By senthilrg in forum Queries
    Replies: 3
    Last Post: 12-18-2009, 09:24 PM

Tags for this Thread

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