Noob needs help badly

Jdreyfus

Registered User.
Local time
Today, 12:13
Joined
Jun 19, 2008
Messages
27
I've been attempting to have a field within a form check whether or not a duplicate record exists and deliver a message immediately after you navigate away from the field. I'm uncertain whether the code I have is what I really need, it's the only code so far however that's produced something close to what I'd like, unfortunately it seems to think every record entered is a duplicate one. I'm sure there is an obvious error in my method, but I know virtually nothing about VB, can anyone point me straight???

Code:
Private Sub YC_TAG_BeforeUpdate(Cancel As Integer)
Dim YC_TAG As Integer
YC_TAG = DCount("[YC_TAG]", "Assets", "[YC_TAG] =" & Me.YC_TAG)
If YC_TAG > 0 Then
MsgBox "Duplicate Present", vbOKOnly
    Cancel = True
    Exit Sub
End If
End Sub
 
You may have introduced some confusion by having the same name for your field, control and variable. It may be checking a different one than you expect. I'd start by changing the control and variable names.
 

Users who are viewing this thread

Back
Top Bottom