UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Dcount To Check For Duplicates, Access 2013    
 
   
tlsn4
post Mar 7 2018, 05:57 PM
Post#1



Posts: 250
Joined: 12-August 03
From: Olympia, WA


Hey all,

Just trying to get this to work and I keep getting a 2766 automation error. This is on my BeforeUpdate event on my main form. Any ideas?

CODE
    If DCount("*", "tblAAP", "ContractNumber=" & Me.ContractNumber) > 0 Then
        MsgBox "WARNING!!!" & vbCrLf & vbCrLf & _
            "The contract number you entered already exists." & vbCrLf & vbCrLf & _
            "Please try again" & vbCrLf & vbCrLf & _
            "Click OK to correct.", vbCritical, "Duplicate Contract Number"
        Me.ContractNumber.SetFocus
        Cancel = True
    End If


Thanks
Taz
Go to the top of the page
 
tlsn4
post Mar 7 2018, 06:10 PM
Post#2



Posts: 250
Joined: 12-August 03
From: Olympia, WA


Got it fixed. Just forgot to add a couple quotation marks.

CODE
    If DCount("*", "tblAAP", "ContractNumber='" & Me.ContractNumber &"'") > 0 Then
        MsgBox "WARNING!!!" & vbCrLf & vbCrLf & _
            "The contract number you entered already exists." & vbCrLf & vbCrLf & _
            "Please try again" & vbCrLf & vbCrLf & _
            "Click OK to correct.", vbCritical, "Duplicate Contract Number"
        Me.ContractNumber.SetFocus
        Cancel = True
    End If


Thanks
Taz
Go to the top of the page
 
missinglinq
post Mar 7 2018, 07:08 PM
Post#3



Posts: 4,566
Joined: 11-November 02



Your ContractNumber is obviously defined as a Text Datatype...while your original code is the correct syntax for a Field defined as a Number.

It's always good to solve your own problems, isn't it? thumbup.gif

Linq ;0)>
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    9th December 2018 - 11:20 PM