Solved

adodc1.recordset.find

Posted on 2010-11-24
5
1,579 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
  • 2
  • 2
5 Comments
 
LVL 84
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 500 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

773 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