I want to check for duplicate date before upadating the table. In the Update Button Click Event I have used the follwoing code forcchecking duplicate

sbaud2003

Member
Local time
Tomorrow, 02:38
Joined
Apr 5, 2020
Messages
186
the code is not working , even no error is there, records gets updated with duplicate date?- Please Help anyone

Dim NewDt As Date
Dim stLinkCriteria As String
NewDt = Me.txtfrom.value
stLinkCriteria = "[FROM] = " & NewID
If Me.txtfrom = DLookup("[FROM]", "[REPORT_LEAVE]", stLinkCriteria) Then
MsgBox "This Date:" & [NewID] & ", already exist taken in the Database, " _
& vbCr & vbCr & "Please enter a new Date", vbInformation, "HELLO USER.... DUPLICATE INFORMATION"
Me.Undo

End If
 
put your code in the BeforeUpdate event of your Form (not on any button)
 
Why would you think a date would have the same ID?, surely you would look for the date?
 
Check your spellings, you declare NewDt varaible yet you use undeclared NewID....
 
Please do us all a favour.
Put your code between code tags. Not bold tags.
 

Users who are viewing this thread

Back
Top Bottom