I have added a following condition
If RS.Fields(0) & "" = "" Then
Please Try following code
Private Sub txtUserCode_Validate(Cancel As Boolean)
If RS!ID = txtUserCode.Text Then
SQL = "SELECT NAME,PRIVILEDGE FROM ADMIN WHERE CODE=" & txtUserCode.Text
Set RS = CN.Execute(SQL)
If RS.Fields(0) & "" = "" Then
MsgBox "ENTER VALID NO"
txtUserCode.Text = ""
Cancel = True
ELSE
txtUserName.Text = RS!NAME
End If
End Sub