Link to home
Start Free TrialLog in
Avatar of TechLad
TechLadFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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 ?
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

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

Avatar of TechLad

ASKER

Sorry I dont get this, I'm thick. Whats all the Yourconnection ?
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) & "' "
Avatar of TechLad

ASKER

Cool that worked, one last thing is there a way of displaying a message if theres no record found ?
ASKER CERTIFIED SOLUTION
Avatar of Brook Braswell
Brook Braswell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial