Results 1 to 5 of 5
  1. #1
    whojstall11 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Sep 2011
    Posts
    57

    DCOUNT Find Duplicate values

    Can anybody telll me where I went wrong: Amount= Number, Request Date = Date/time, Everything else is a text



    Code:
    stLinkCriteria = "[Amount]= " & Me.Amount & "[Cardholder Name] = '" & Me.[Cardholder Name] & "'" & "[Request Date] = #" & Me.[Request Date] & "#" & "[Card Number] = '" & [Card Number] & "'"
    
    Dim intRe As Integer
    If DCount("*", "[MultiAMastetbl]", stLinkCriteria) > 0 Then
           intRe = MsgBox("Duplicate Information. Are you sure you want to continue? ", vbOKCancel, "")
    My error is attached Click image for larger version. 

Name:	duperror.png 
Views:	12 
Size:	6.0 KB 
ID:	16053

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    If you look at the message, you can see that you did not include spaces where needed when you concatenated text with your variables.

    so this, for instance
    Amount]= " & Me.Amount & "[Cardholder

    should be this
    Amount]= " & Me.Amount & " [Cardholder

    because it is causing your string to result with
    103[Cardholder

    instead of
    103 [Cardholder

    Then you will also need an operator to tell SQL what the heck....
    stLinkCriteria = "[Amount]= " & Me.Amount & " AND [Cardholder Name] = '" & Me.[Cardholder Name] & "'"

    There are other syntax issues too

  3. #3
    whojstall11 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Sep 2011
    Posts
    57
    Yes thank you the nasty error message disappearred but it not working like I thought it should. Instead of the error message coming up IF there is an duplicate record in fields ([Amount],[Cardholder Name],[Request Date],[Card Number]) it just pops up whenever I add a record.

  4. #4
    whojstall11 is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Sep 2011
    Posts
    57
    Nevermind that was a stupid question thanks

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Ahuh, perhaps you can use the immediate window to analyze your stLinkCriteria string before moving onto troubleshooting other blocks of code.

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

Similar Threads

  1. Dcount prevent duplicate
    By ayamali in forum Programming
    Replies: 20
    Last Post: 04-16-2013, 09:31 PM
  2. Replies: 1
    Last Post: 02-18-2013, 02:11 PM
  3. Replies: 5
    Last Post: 01-29-2013, 03:38 PM
  4. Replies: 4
    Last Post: 11-17-2012, 03:07 PM
  5. Replies: 1
    Last Post: 04-30-2012, 08:42 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