Preventing duplicate entery including spaces and case sensitivity - ms access (1 Viewer)

Ihk

Member
Local time
Today, 06:37
Joined
Apr 7, 2020
Messages
280
Want to prevent duplicate entery including extra/less spaces.
with follwoing code, duplicate entery is prevented including case sensitity.
I am wondering if it is possible to prevent with extra or less space. For example: Test1 or Test 1
1st one has no space, 2nd one has space. is it also possible to prevent this, if user manupulate a word while data entery.
My current code is
Code:
If Not IsNull(DLookup("[Catalogue]", "ArticleDetails", "[Catalogue] = '" & Me.txtCatalogue.Value & "'")) Then
Cancel = True
Msgbox "msg for duplicate"
Else
End if
Thanks
 

Gasman

Enthusiastic Amateur
Local time
Today, 05:37
Joined
Sep 21, 2011
Messages
14,238
Remove all spaces with Replace() and then compare.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 12:37
Joined
May 7, 2009
Messages
19,229
use DCount instead of DLookup, it will return 0 if not found, or a Number if Found:

Code:
If DCount("1", "ArticleDetails", "Replace([Catalogue], '  ','') = '" & Replace$(Me.txtCatalogue.Value," ","") & "'") <> 0 Then
Cancel = True
Msgbox "msg for duplicate"
Else
End if
 

Ihk

Member
Local time
Today, 06:37
Joined
Apr 7, 2020
Messages
280
The question is data is already in database.
Catalogue number from different companies is in different format, some with spaces some without, some capital, some not, some with special characters etc etc.
I dont have to change that, but when users are also allowed to add new catalogue if wont exist.
In that case with "Not IsNull dlook up", it does not allow users to add duplicate, also case sensitive, still we noticed some of the users Add some space or reduce some space and add the record.
Can this be prevented?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 23:37
Joined
Feb 28, 2001
Messages
27,148
Your problem is that you have already allowed the possibility of oddball spacing based on the already-entered numbers from different companies. Did you limit the number of spaces in those entries? If you didn't, then I would have to say "Not easily if at all."

If you did a sweep of your DB to adjust the oddball cases first, you could then reasonably do it a simple way. I would remove all doubled spaces and all leading and trailing spaces from the extant entries. Then you could apply the TRIM() and REPLACE() functions to clean up the new input before checking for duplicates. As for the case sensitivity, this can be done with the OPTION COMPARE setting that can be set to BINARY, which means case matters. There might be other things you could do as well, but they would depend on how Draconian you wanted to be. The "Test1" vs "Test 1" case would require a strict rule about "no interior spaces at all" and I gather that you don't think you can make that rule.
 

moke123

AWF VIP
Local time
Today, 00:37
Joined
Jan 11, 2013
Messages
3,912
What about doing a comparison to existing data and present the user with a list of similiar entries to either select or ignore?
Perhaps using levenschtein distance?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 00:37
Joined
May 21, 2018
Messages
8,525
Something like this might work
or
or
 

jdraw

Super Moderator
Staff member
Local time
Today, 00:37
Joined
Jan 23, 2006
Messages
15,379
I agree with George. We used to call it IEH-IBall for those ex-IBMers out there.
 

Ihk

Member
Local time
Today, 06:37
Joined
Apr 7, 2020
Messages
280
Sorry I was travelling and could not get in.
I am very thankful for all of you for your helpful suggestions.
 

Ihk

Member
Local time
Today, 06:37
Joined
Apr 7, 2020
Messages
280
use DCount instead of DLookup, it will return 0 if not found, or a Number if Found:

Code:
If DCount("1", "ArticleDetails", "Replace([Catalogue], '  ','') = '" & Replace$(Me.txtCatalogue.Value," ","") & "'") <> 0 Then
Cancel = True
Msgbox "msg for duplicate"
Else
End if
Thank you very much. I tried this, this worked when put spaces in between and tried to enter data, it was not possible.
But this was working only for pure numbers like 1234 or 123 4 , either of these is considered as duplicate. But this does not detect any type of text or text+numerical as duplicate.
 

Ihk

Member
Local time
Today, 06:37
Joined
Apr 7, 2020
Messages
280
I must have to say here, my current data is correct. There is no problem, all correction have been taken place side by side. Now the question was about next, not allow user to enter duplicate values.
Still I was able to manage this by "Not IsNull(DLookup...." above mentioned. This is case sensetive and prompts users for duplicate entery, this also stops leading and trailing spaces.
But it does not prompt when there is any space in between.
I tried above mentioned at post 3 by @arnelgp ,
use DCount instead of DLookup,
This stops duplicate entery (including between spaces) but only for numerical entery.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 23:37
Joined
Feb 28, 2001
Messages
27,148
The samples you showed us do not appear to contain embedded spaces. Can't tell if they have leading/trailing spaces. However, if you TRIM$ the input before testing for duplicates, that should match correctly most of the time. The only time you get skunked is if the stored data has leading or trailing spaces.
 

Users who are viewing this thread

Top Bottom