Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search an entered value in the Table

Status
Not open for further replies.

rpk2006

Technical User
Apr 24, 2002
225
0
0
IN
I want to search a name in my table, and if the name is found it should display it.

I have done following:

--------------------------------------
Private Sub cmdSearch_Click()
1 Dim rst as ADODB.Recordset
2 Dim strQuery as String
3 Dim newUname as String

4 Set rst = New ADODB.Recordset

5 newUname = InputBox ("Enter New Username","New")
6 strQuery = "Select username from rpm_users where _
7 username = '" & newUname & "'"

8 rst = cn.Execute (strQuery)

9 If rst!username = newUname Then
10 MsgBox "User Already exists"
11 Endif
End Sub
----------------------------------------

But it is not doing the job. It displays some error at line 9.
Please suggest how to retrieve the searched username.

Thanks.
There is always a new solution for the same problem.

Anonymous
 
Try a rst.MoveFirst before line 9 Let me know if this helps
________________________________________________________________
If you are worried about how to post, please check out FAQ222-2244 first

'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
 
After line 8 you need to check to see if any records have been returned

If rst.eof and rst.bof then
msgbox "none returned"
ELSE
the rest of the code
 

Change:
9 If rst!username = newUname Then

To:

9 If Not rst.EOF then [/b][/i][/u]*******************************************************[sub]
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 

Ok Paddyo, you beat me to it!

Anyways, I meant to say:

9 If rst.EOF then [/b][/i][/u]*******************************************************[sub]
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
or u can use if .recordcount=0 then

lol

there are so many ways to do this type of comparisons

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top