Solved

adodc1.recordset.find

Posted on 2010-11-24
5
1,670 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

821 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