Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find method in ADO 1

Status
Not open for further replies.

seaport

MIS
Jan 5, 2000
923
US
I am using ADO in Access2000. I find out that with ADO, the find method can only search one field. <br><br>for example: rst.find &quot;lastname='&quot; & jack & &quot;'&quot;<br><br>So how can I search two fields together in ADO? (for example, lastname and firstname together)<br><br>Thanks in advance.<br><br>seaport
 
Try this:<br><br>rst.FindFirst &quot;lastname='&quot; & jack & &quot;' AND Firstname = '&quot; & Jill & &quot;'&quot;<br><br>I have found a better way is to create a SQL String with the criteria in the where portion. Then open the recordset using the SQL string. This way you don't have to use the FindFirst method at all.<br><br>For example:<br><br>Dim strSQL as String<br><br>strSQL = &quot;SELECT * FROM YourTable WHERE Lastname = 'Smith' AND Firstname = 'Andrew'&quot;<br><br>Now open the Recordset using the strSQL instead of opening a table. Now you can simply check to see if rs.recordcount &gt; 0 OR rs.EOF, and then do what you need to do.<br><br>If you want to make it dynamic, maybe read a Lastname and Firstname field on a form, then use this string:<br><br>strSQL = &quot;SELECT * FROM YourTable WHERE Lastname = '&quot; & Me.Lastname & &quot;' AND Firstname = '&quot; & Me.Firstname & &quot;'&quot;<br><br>Using this method only returns the records you want rather than return the whole table, and then have to search it. <p>Jim Lunde<br><a href=mailto:compugeeks@hotmail.com>compugeeks@hotmail.com</a><br><a href= Application Development
 
Thanks jimmythegeek,<br><br>&quot;To create a SQL String with the criteria in the where portion&quot; is a good idea. <br><br>seaport
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top