R
Ray
I have a table with membership numbers. The field is called Mbr No. I have
a form with the field Mbr No in it. When I am entering new records I want
the code to check if the number already exists and if so print an error
message. Here is the code I have been trying to work out.
Private Sub Mbr_No_BeforeUpdate(Cancel As Integer)
If DCount("[mbr no]", "members", "[mbr no]>0") Then
MsgBox "This Member Number " & Me.[Mbr No].Value _
& " has already been used!", vbExclamation, "Duplicate Member #"
Cancel = True
End If
End Sub
Unfortunately (for me) this returns the "already used" message whether it is
true or not.
My instinct tells me it has to have something to do with identifying the
last Mbr No as being in the form but I have tried variants like Me.[Mbr No]
(see below) with no luck.
Private Sub Mbr_No_BeforeUpdate(Cancel As Integer)
If DCount("[mbr no]", "members", "Me.[mbr no]>0") Then
MsgBox "This Member Number " & Me.[Mbr No].Value _
& " has already been used!", vbExclamation, "Duplicate Member #"
Cancel = True
End If
End Sub
Please help.
Thank you.
Ray
a form with the field Mbr No in it. When I am entering new records I want
the code to check if the number already exists and if so print an error
message. Here is the code I have been trying to work out.
Private Sub Mbr_No_BeforeUpdate(Cancel As Integer)
If DCount("[mbr no]", "members", "[mbr no]>0") Then
MsgBox "This Member Number " & Me.[Mbr No].Value _
& " has already been used!", vbExclamation, "Duplicate Member #"
Cancel = True
End If
End Sub
Unfortunately (for me) this returns the "already used" message whether it is
true or not.
My instinct tells me it has to have something to do with identifying the
last Mbr No as being in the form but I have tried variants like Me.[Mbr No]
(see below) with no luck.
Private Sub Mbr_No_BeforeUpdate(Cancel As Integer)
If DCount("[mbr no]", "members", "Me.[mbr no]>0") Then
MsgBox "This Member Number " & Me.[Mbr No].Value _
& " has already been used!", vbExclamation, "Duplicate Member #"
Cancel = True
End If
End Sub
Please help.
Thank you.
Ray