Home All Groups Group Topic Archive Search About

ADO Recordset Find method Problem

Author
20 Feb 2009 4:37 AM
hon123456
Dear all,

            I have a Recordset  RST with two rows with the same Data
like follows:


             Company

  1.         ABC
  2.         ABC

        Now I use RST.Find "Company="ABC" to find the Record. After
finding the first record.
I would like to find the second record use find too.  The code is as
follows:

RST.Find "Company="ABC"
RST.Find "Company="ABC"

But I found that in when the Second Find executes. The RST still
points to the first record. It does not move to the second Record. Is
find method can only find one record and cannot find next record. Or
there are somethings I need to set in the RST properties just like
CursorLocation
in order to make the find can move to the second Record.

Thanks

Author
20 Feb 2009 5:23 AM
Ralph
Show quote Hide quote
"hon123456" <peterhon***@yahoo.com.hk> wrote in message
news:a5b1a0ed-d903-4013-91bc-3dec10d5a290@g1g2000pra.googlegroups.com...
> Dear all,
>
>             I have a Recordset  RST with two rows with the same Data
> like follows:
>
>
>              Company
>
>   1.         ABC
>   2.         ABC
>
>         Now I use RST.Find "Company="ABC" to find the Record. After
> finding the first record.
> I would like to find the second record use find too.  The code is as
> follows:
>
> RST.Find "Company="ABC"
> RST.Find "Company="ABC"
>
> But I found that in when the Second Find executes. The RST still
> points to the first record. It does not move to the second Record. Is
> find method can only find one record and cannot find next record. Or
> there are somethings I need to set in the RST properties just like
> CursorLocation
> in order to make the find can move to the second Record.
>

The ADO Find method takes 4 parameters.
http://msdn.microsoft.com/en-us/library/ms917727.aspx
Author
20 Feb 2009 5:50 AM
hon123456
Thanks Ralph

Use all 4 parameters , but Find still not move to the second record.

RST.Find "Company = 'ABC', 0, adSearchForward, 0

Please help.

Thanks
Author
20 Feb 2009 6:35 AM
hon123456
On 2?$B7n?(B20?$BF|?(B, ?$B2<8a?(B1?$B;~?(B50?$BJ,?(B, hon123456 <peterhon***@yahoo.com.hk> wrote:
> Thanks Ralph
>
> Use all 4 parameters , but Find still not move to the second record.
>
> RST.Find "Company = 'ABC', 0, adSearchForward, 0
>
> Please help.
>
> Thanks

Since my recordset is using adUseClient CursorLocation. So is that
mean I need
to install MDAC 2.8 to let Find method work. And include the MDAC in
my project
to Find method work. Or some other setting that I need to set .

Thanks
Author
20 Feb 2009 6:43 AM
hon123456
On 2?$B7n?(B20?$BF|?(B, ?$B2<8a?(B2?$B;~?(B35?$BJ,?(B, hon123456 <peterhon***@yahoo.com.hk> wrote:
Show quoteHide quote
> On 2?$B7n?(B20?$BF|?(B, ?$B2<8a?(B1?$B;~?(B50?$BJ,?(B, hon123456 <peterhon***@yahoo.com.hk> wrote:
>
> > Thanks Ralph
>
> > Use all 4 parameters , but Find still not move to the second record.
>
> > RST.Find "Company = 'ABC', 0, adSearchForward, 0
>
> > Please help.
>
> > Thanks
>
> Since my recordset is using adUseClient CursorLocation. So is that
> mean I need
> to install MDAC 2.8 to let Find method work. And include the MDAC in
> my project
> to Find method work. Or some other setting that I need to set .
>
> Thanks

My window is XP SP2. It does not need to install MDAC. So why
recordset find
method cannot find the second record? Any Idea? Or Find can only work
with Server Cursor location.

Thanks
Author
20 Feb 2009 7:00 AM
hon123456
On 2?$B7n?(B20?$BF|?(B, ?$B2<8a?(B2?$B;~?(B43?$BJ,?(B, hon123456 <peterhon***@yahoo.com.hk> wrote:
Show quoteHide quote
> On 2?$B7n?(B20?$BF|?(B, ?$B2<8a?(B2?$B;~?(B35?$BJ,?(B, hon123456 <peterhon***@yahoo.com.hk> wrote:
>
>
>
>
>
> > On 2?$B7n?(B20?$BF|?(B, ?$B2<8a?(B1?$B;~?(B50?$BJ,?(B, hon123456 <peterhon***@yahoo.com.hk> wrote:
>
> > > Thanks Ralph
>
> > > Use all 4 parameters , but Find still not move to the second record.
>
> > > RST.Find "Company = 'ABC', 0, adSearchForward, 0
>
> > > Please help.
>
> > > Thanks
>
> > Since my recordset is using adUseClient CursorLocation. So is that
> > mean I need
> > to install MDAC 2.8 to let Find method work. And include the MDAC in
> > my project
> > to Find method work. Or some other setting that I need to set .
>
> > Thanks
>
> My window is XP SP2. It does not need to install MDAC. So why
> recordset find
> method cannot find the second record? Any Idea? Or Find can only work
> with Server Cursor location.
>
> Thanks- ?$Bp,i6Ho0zMQJ8;z?(B -
>
> - ?$Bp}<(Ho0zMQJ8;z?(B -

I discover that Find will only works when it is preceded by
rst.movefirst or
rst.movelast. Find method even will not work after  rst.movenext or
rst.moveprevious. What should I do to let Find method to move to the
second Record. Thanks
Author
20 Feb 2009 7:09 AM
hon123456
On 2?$B7n?(B20?$BF|?(B, ?$B2<8a?(B3?$B;~?(B00?$BJ,?(B, hon123456 <peterhon***@yahoo.com.hk> wrote:
Show quoteHide quote
> On 2?$B7n?(B20?$BF|?(B, ?$B2<8a?(B2?$B;~?(B43?$BJ,?(B, hon123456 <peterhon***@yahoo.com.hk> wrote:
>
>
>
>
>
> > On 2?$B7n?(B20?$BF|?(B, ?$B2<8a?(B2?$B;~?(B35?$BJ,?(B, hon123456 <peterhon***@yahoo.com.hk> wrote:
>
> > > On 2?$B7n?(B20?$BF|?(B, ?$B2<8a?(B1?$B;~?(B50?$BJ,?(B, hon123456 <peterhon***@yahoo.com.hk> wrote:
>
> > > > Thanks Ralph
>
> > > > Use all 4 parameters , but Find still not move to the second record.
>
> > > > RST.Find "Company = 'ABC', 0, adSearchForward, 0
>
> > > > Please help.
>
> > > > Thanks
>
> > > Since my recordset is using adUseClient CursorLocation. So is that
> > > mean I need
> > > to install MDAC 2.8 to let Find method work. And include the MDAC in
> > > my project
> > > to Find method work. Or some other setting that I need to set .
>
> > > Thanks
>
> > My window is XP SP2. It does not need to install MDAC. So why
> > recordset find
> > method cannot find the second record? Any Idea? Or Find can only work
> > with Server Cursor location.
>
> > Thanks- ?$Bp,i6Ho0zMQJ8;z?(B -
>
> > - ?$Bp}<(Ho0zMQJ8;z?(B -
>
> I discover that Find will only works when it is preceded by
> rst.movefirst or
> rst.movelast. Find method even will not work after  rst.movenext or
> rst.moveprevious. What should I do to let Find method to move to the
> second Record. Thanks- ?$Bp,i6Ho0zMQJ8;z?(B -
>
> - ?$Bp}<(Ho0zMQJ8;z?(B -

I have find a solution to the problem

The code I used is
RST.MoveFirst
RST.Find "Company="ABC"
RST.moveprevious
RST.movenext
Rst.movenext
RST.Find "Company="ABC"


Then the find can find the second record.

Thanks
Author
20 Feb 2009 2:50 PM
Ralph
Show quote Hide quote
"hon123456" <peterhon***@yahoo.com.hk> wrote in message
news:9ec3f340-c40c-4069-82f9-a412d5848807@u39g2000prn.googlegroups.com...
>
> I have find a solution to the problem
>
> The code I used is
> RST.MoveFirst
> RST.Find "Company="ABC"
> RST.moveprevious
> RST.movenext
> Rst.movenext
> RST.Find "Company="ABC"
>
>
> Then the find can find the second record.
>
> Thanks
>

Apparently only the first couple of sentances of my post showed up. After
the link I went on to say ...

"This may help, but frankly ADO's .Find method is flacky. It often has
trouble determining current record location or where it should start looking
from."

.... a long winded explanation mercifully snipped as you have already
discoverd the common work-arounds, or ugly gyrations, one too often finds
themselves forced into doing. To make it worse - subtle differences in
behavior will be found with different Providers. It performs it's designed
mission of "finding the first record" in a Recordset that has already been
opened and "moved into", but even then can fail if the target is the first
or last record.

Because of this .Find is best avoided for those scenarios where you need to
'find' multiple records. Performance wise you are better off
1) Sorting the original query using an Order By clause. Use .Find for the
first record and then loop until the target column is no longer valid. ...
     ' psuedocode
     .MoveFirst
     .Find target
     While target = "something"
         DoStuffWithRecord
         .MoveNext
     Wend
2) Use ADO's .Sort method, then do the above
3) or re-query the data using the target in a Where clause, then looping
through the new Recordset. (Believe it or not - often faster)

hth
-ralph