Results 1 to 3 of 3
  1. #1
    quicova is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2013
    Posts
    53

    Check of duplicates by name in a form

    Hello everyone.

    I'm trying to check for duplicate item names when adding a new item in a form.
    I created an beforeupdate event but I'm getting an error and can't see why.

    I'm using the DCount function.

    Code:
    Private Sub Part_Name_BeforeUpdate(Cancel As Integer)
       
        Dim criteria As String
        criteria = _
           "Part_Name = " & Me.Part_Name & " "
        
        If DCount("Part_Name", "Part_Database", criteria) > 0 Then
           MsgBox "This Part already exists, please Add a diferent part name or edit the Existing Part"
           Me.Undo
        End If
       
    End Sub
    I get a Run-time error 2471:
    the expression you entered as a query parameter produced this error:
    "testname"


    if I change the code to:



    Code:
    If DCount("Part_Name", "Part_Database", Me.Part_Name) > 0 Then
           MsgBox "This Part already exists, please Add a different part name or edit the Existing Part"
           Me.Undo
        End If
    this if statement is always true.

    Can anyone give me a hand with this?
    I did the same but using ID and it worked, but can't use IDs for this one.

    Thanks so much

  2. #2
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    It looks like just missing the """" or "'" since is a tex field. Space is not needed as well.

    criteria = _
    "Part_Name = """ & Me.Part_Name & """"

    Hope that will solve the problem.

  3. #3
    quicova is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2013
    Posts
    53
    nice it worked.... thanks so much

    It is always the little things

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

Similar Threads

  1. Duplicates in a form but not the query
    By tcheck in forum Access
    Replies: 4
    Last Post: 04-09-2013, 11:12 AM
  2. Replies: 2
    Last Post: 07-12-2012, 12:46 AM
  3. Hide Duplicates In Look Up Form
    By PonderingAccess in forum Queries
    Replies: 2
    Last Post: 09-30-2010, 12:23 PM
  4. To check or Un-Check all Boxes in a form
    By devcon in forum Forms
    Replies: 7
    Last Post: 05-01-2010, 12:03 AM
  5. Replies: 0
    Last Post: 01-08-2009, 05:49 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