adodc1.recordset.find

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 ?
TechLadAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Brook BraswellConnect With a Mentor Application Development ManagerCommented:



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
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
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
 
TechLadAuthor Commented:
Sorry I dont get this, I'm thick. Whats all the Yourconnection ?
0
 
Brook BraswellApplication Development ManagerCommented:
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
 
TechLadAuthor Commented:
Cool that worked, one last thing is there a way of displaying a message if theres no record found ?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.