Prevent Duplicate in table -Before Update of Textbox (1 Viewer)

eka24

Registered User.
Local time
Today, 09:01
Joined
Oct 2, 2017
Messages
41
Please I have a Table "tblSubmission" with Field "ClNo"
I found the code on this platform which works fine when make manual entry into the textfield "ClNo" which prevent duplicate in the table "tblsubmission".

My Problem: ClNo is a concateated field which derives from three other textboxes. Because of this, the before update of ClNo doesnt work to prevent duplicate in the table


Private Sub ClNo_BeforeUpdate(Cancel As Integer)
Dim Answer As Variant
Answer = DLookup("[ClNo]", "tblSubmission", "[ClNo] = '" & Me.ClNo & "'")
If Not IsNull(Answer) Then
MsgBox "Duplicate Record, Already exist" & vbCrLf & "Please Check and try again.", vbCritical + vbOKOnly + vbDefaultButton1, "Duplicate"

'Cancel = True
Me.Undo


Else:
End If
End Sub
 

June7

AWF VIP
Local time
Today, 08:01
Joined
Mar 9, 2014
Messages
5,490
Would have to use event of the 3 textboxes which I presume are user input or form BeforeUpdate.
 

eka24

Registered User.
Local time
Today, 09:01
Joined
Oct 2, 2017
Messages
41
OK I will try and get back
 

moke123

AWF VIP
Local time
Today, 12:01
Joined
Jan 11, 2013
Messages
3,935
ClNo is a concateated field which derives from three other textboxes. Because of this, the before update of ClNo doesnt work to prevent duplicate in the table

Is the data in the 3 other text boxes being saved to the table?
Is there a specific reason to save a concatenated field?
Normally you would not save it but would assemble it as needed for display. For instance you would not have a table with First Name, Last Name and Full Name. You would concatenate the Full Name when needed for display.
 

missinglinq

AWF VIP
Local time
Today, 12:01
Joined
Jun 20, 2003
Messages
6,423
Assuming that the three Fields are being saved to the Table...you just need to check the three Fields, rather than ClNo, which, has been said, shouldn't really be saved in the Table...like this

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)

 If DCount("*", "tblSubmission", "[Field1] & [Field2] & [Field3] = '" & Me.Field1 & Me.Field2 & Me.Field3 & "'") > 0 Then

   MsgBox "Duplicate Record, Already exist" & vbCrLf & "Please Check and try again.", vbCritical + vbOKOnly + vbDefaultButton1, "Duplicate"

   Cancel = True
 End If

End Sub
Replacing Field1, Field2, Field3 with your actual names.

Linq ;0)>
 
Last edited:

eka24

Registered User.
Local time
Today, 09:01
Joined
Oct 2, 2017
Messages
41
thank very much all of you. Richmond's helped me
 

Users who are viewing this thread

Top Bottom