I changed the code as under:
If IsNull(Me![DyNo]) Then
Me![DyNo] = Nz(DMax("[DyNo]", "[DiaryTable]", "[TheYear]='" & Year(Date) & "'"), 0) + 1
End If
Me![DyNo] = [DyNo]
With this changed code, I am unable to do data entry after No.10. After 10, it repeatedly gives No.10. Please help.