swell
Member
- Local time
- Today, 12:23
- Joined
- Mar 10, 2020
- Messages
- 77
Hi,
I am having problems with a data entry form. I am trying to prevent duplicate entries in a table the criteria has to be unique over 4 fields.
Namely "BookNumber", "Date of Activity", "Activity", "Notes" these are the only fields I can combine to form a unique record index.
I have an index of these fields which is set to no duplicates, it doesn't produce the normal error message for duplicates. (this used to work not sure why it has stopped working).
On investigation of the problem I have seen many suggestions how duplicates would be better handled using "BeforeUpdate" in VBA as can be seen from the following snippet of my code I am using the DLookup function as suggested in this forum in testing the code I get the following error.
Run time error 2471
The expression you entered as a query returned the following error: "nul"
I wouldn't be surprised if my construct of the code is my problem.
Is there a better way to handle duplicates?
I thought checking for duplicates before or on entry to the "Hours" field would be a better place to check rather than when the user clicks the "Enter record" button! Thoughts and suggestions on this would also be appreciated.
Here is a snip of the Table design
--
The portion of code in question
I am having problems with a data entry form. I am trying to prevent duplicate entries in a table the criteria has to be unique over 4 fields.
Namely "BookNumber", "Date of Activity", "Activity", "Notes" these are the only fields I can combine to form a unique record index.
I have an index of these fields which is set to no duplicates, it doesn't produce the normal error message for duplicates. (this used to work not sure why it has stopped working).
On investigation of the problem I have seen many suggestions how duplicates would be better handled using "BeforeUpdate" in VBA as can be seen from the following snippet of my code I am using the DLookup function as suggested in this forum in testing the code I get the following error.
Run time error 2471
The expression you entered as a query returned the following error: "nul"
I wouldn't be surprised if my construct of the code is my problem.
Is there a better way to handle duplicates?
I thought checking for duplicates before or on entry to the "Hours" field would be a better place to check rather than when the user clicks the "Enter record" button! Thoughts and suggestions on this would also be appreciated.
Here is a snip of the Table design
--
The portion of code in question
Code:
Answer = DLookup("[Entry ID]", "Member Activity", "[BookNumber]<>" & BookNumber & _
" AND BookNumber=" & BookNumber & " AND [Date of Activity]=" & [Date of Activity] & _
" And Notes =" & Notes & " AND Activity=" & Activity)