something like this
-
Private Sub CategoryName_BeforeUpdate(Cancel As Integer)
-
Dim Answer As Variant
-
Answer = DLookup("[CategoryName]", _
-
"tbl_Category", _
-
"[CategoryName] = '" & Me.CategoryName & "'")
-
If Not IsNull(Answer) Then
-
MsgBox "Hi-Tech sysadmin reports that Duplicate Category Name Found, " _
-
& "Please press ok and try again. ", _
-
vbCritical + vbOKOnly + vbDefaultButton1, _
-
"Hi-Tech sysadmin, Duplicate Category Found"
-
Cancel = True
-
Me.CategoryName.Undo
-
End If
-
End Sub
-
-
You should write your own code something like that in your projects.
When trying to debug problems, readabilty can make all the difference
between a speedy fix and a hair pulling experience.
After reading the above code I see that you are trying to stop entry of duplicate categorynames, so I must have miss-understood your question with my first suggestion.
Don't forget, you can put breakpoints on each line of code.
That way, you can step through each line of code and watch what is happening.
Always helps me to find hard to find problems.