?
Solved

Alternative to Find Method in VBA

Posted on 2005-03-31
7
Medium Priority
?
897 Views
Last Modified: 2008-02-01
I'm having a big problem with the Find Method in VBA with large recordsets. With small recordsets, the following codes works very well:

For Each vntAny In astrLabels
   
   If vntAny <> "" Then
     
      rstScores.MoveFirst
     
      'Looking for a non-null value
      rstScores.Find ("" & vntAny & " <> Null")
     
      'If we find a non-null value, then we can move on to the rest of the code
      If rstScores.EOF = False Then
     
         rstScores.MoveFirst
         
         'Looking for an "N"
         rstScores.Find ("" & vntAny & " = 'N'")
         
         'If we don't find the "N," we want that label in our final label array
         If rstScores.EOF = True Then
               astrLabelsKeep(intArrayPos) = vntAny
               intArrayPos = intArrayPos + 1
         End If
     
      End If
   
   End If
   
Next vntAny

With large recordsets, the above code crashes every time. Can anyone suggest modifications or alternatives? Thanks.
0
Comment
Question by:Feyo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 13673150
I take it you are working with ADO recordsets?
0
 
LVL 4

Author Comment

by:Feyo
ID: 13673155
Yes, I am.
0
 
LVL 41

Assisted Solution

by:shanesuebsahakarn
shanesuebsahakarn earned 375 total points
ID: 13673202
You could try the Seek method - I haven't used it myself, but have a look at the documentation in the Help file - there's an example there.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 51

Expert Comment

by:Steve Bink
ID: 13673625
The Seek method in ADO requires that you use an index, a server-side cursor, and the recordset must have been opened using adCmdTableDirect as the CommandType.  Also, I'm not sure if it would be possible to search for a NULL value, but experimentation will tell for sure.  Your better option may to use SQL SELECT statements.
0
 
LVL 4

Author Comment

by:Feyo
ID: 13673757
I think you mentioned that yesterday or the day before, routinet. I've been messing around with them and it seems they are much more efficient, even opening and closing a whole bunch of times, than the find method. I'll keep at it to see for sure. Thanks.
0
 
LVL 51

Accepted Solution

by:
Steve Bink earned 675 total points
ID: 13675272
Seek is much more efficient than Find, since it relies on table indices instead of a 1-by-1 search of the data.  If used properly, you will no doubt see a very large performance benefit from using it over Find.  If you can verify that it will identify NULL values in an indexed field, please post that information.
0
 
LVL 4

Author Comment

by:Feyo
ID: 13778284
Couldn't get the seek method to work for my purposes, but I learned alot in the process. I experimented and it is much faster than find. Can't verify that it will identify NULL values in an index field though. Thank you for the guidance.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Suggested Courses

800 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