Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
VB
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)
    txtUserName.Text = RS!NAME
Else
    MsgBox "ENTER VALID NO"
            txtUserCode.Text = ""
                        Cancel = True
End If
End Sub


In this code I want to execute like:

[1] If I enter the ID present in table then it'll show info but it's considering 1st record (RS!ID(0)) only not the next one

[2] If I enter the ID which is not present in table then it sh'd not throw error
"3021- Requested operation requires current record" but goto else part.

Please help........
Posted
Updated 20-Feb-13 20:20pm
v3
Comments
RDBurmon 21-Feb-13 2:17am    
From where is "RS!Id" coming in the first line of code?
surkhi 21-Feb-13 2:27am    
RS is my record set and ID field is column of admin table
surkhi 21-Feb-13 2:29am    
I want to search whether inserted no. is the no. in RS(ID) or not?

1 solution

I have added a following condition
If RS.Fields(0) & "" = "" Then
Please Try following code


VB
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
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900