Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

adodc1.recordset.find

Posted on 2010-11-24
5
Medium Priority
?
2,017 Views
Last Modified: 2012-05-10
hi,

How do you use the adodc1.recordset.find or something like that in VB6 to search the table, for the users input on a textbox ?
0
Comment
Question by:TechLad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 85
ID: 34204561
I use the ADODB library, but is should be the same:

Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset

rst.Open "Your SQL", YourConnection

rst.Find, "SomeField= SomeValue"

However, you might be better off with a filtered recordset:

rst.Open "SELECT * FROM SomeTable WHERE SomeField=SomeValue", YourConnection

To reflect user input:

rst.Open "SELECT * FROM SomeTable WHERE SomeField=" & Me.YourTextbox, YourConnection

If "SomeField" is a Text value:

rst.Open "SELECT * FROM SomeTable WHERE SomeField='" & Me.YourTextbox & "'", YourConnection

0
 

Author Comment

by:TechLad
ID: 34204627
Sorry I dont get this, I'm thick. Whats all the Yourconnection ?
0
 
LVL 14

Expert Comment

by:Brook Braswell
ID: 34204962
dim CN as adodb.connection
the YourConnection would be CN

the Object ADODC as you have shown has a recordset that you use the find method...
you must move to the first row of the recordset...

ADODC.Recordset.MoveFirst
ADODC.Recordset.Find "FieldName = '" & trim(txtField.Text) & "' "
0
 

Author Comment

by:TechLad
ID: 34205136
Cool that worked, one last thing is there a way of displaying a message if theres no record found ?
0
 
LVL 14

Accepted Solution

by:
Brook Braswell earned 2000 total points
ID: 34205541



Private Sub SearchData()

IF ADODC.Recordset.RecordCount = 0 then exit sub
ADODC.Recordset.MoveFirst
ADODC.Recordset.Find "FieldName = '" & trim(txtField.Text) & "' "

if ADODC.Recordset.EOF then
   MsgBox "No Find for You !!", vbInformation + vbOKOnly, "Seinfield Messages"
End If       

End Sub
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Make the most of your online learning experience.
Simple Linear Regression
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question