You are right about not having to enter a number in the ItemNo field.
I had been manually entering it myself, but when I started writing the
description of the ItemNo one was entered for me. Very good.
I've put the validation rule in there to liimit the entry to no more
than 3 items per E58No. However, it does not appear to be doing it's
job since the code was able to enter a 4th ItemNo. I will change it
to 1 Or 2 Or 3 to eliiminate the minus numbers, but I don't think that
will solve the *4th ItemNo* problem.
Trap the fourth itemno in the BeforeInsert event instead:
Private Sub Form_BeforeInsert(Cancel As Integer)
If DCount("*", "[Items]", " [E58No] = " & Me![E58No]) >= 3 Then
MsgBox "Only three items per E58 please", vbOKOnly
Cancel = True
Else
Me![ItemNo] = Nz(DMax("[ItemNo]","[Items]","[E58No] = " & Me![E58No])) + 1
End If
End Sub
The problem with the validation rule is that it fires too late - after you've
entered all the data for the record and then try to save it.