Chat with a LIVE Microsoft Access Expert!
 
       
 

         

   

Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
 
Chat with a LIVE Microsoft Access Expert!
Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 02-25-2010, 08:57 PM
selahlynch selahlynch is offline
Registered User
 
Join Date: Jan 2010
Location: Sultanate of Oman
Posts: 63
selahlynch is on a distinguished road
does DAO.FindFirst use table indexes?

I have been using the DAO.FindFirst function in order to find records in my database but it seems to be very slow. I am confused because it seems to perform at the same speed regardless of the indexes on my table.

That is...
Code:
rs.FindFirst (tape = 160 and ffid = 32451 and sline = 2286)
Performs at the same speed regardless of whether have indexes on tape, ffid, and sline or whether I have no indexes at all.

Is this to be expected? Or is something strange going on?
Reply With Quote
Sponsored Links
  #2  
Old 02-25-2010, 10:08 PM
gemma-the-husky's Avatar
gemma-the-husky gemma-the-husky is offline
AWF VIP
 
Join Date: Sep 2006
Location: UK
Posts: 7,419
gemma-the-husky is a jewel in the roughgemma-the-husky is a jewel in the roughgemma-the-husky is a jewel in the roughgemma-the-husky is a jewel in the rough
Re: does DAO.FindFirst use table indexes?

if you do this often then you need an INDEX including those three fields.

then access will decide it can search using that index. If not, it has to search every record (probably in PK order) testing every record until it finds a match or gets to eof.

That is why it is slow.

------------
Seek is optimised, becasue you tell it which index to use, but seek cannot be used on a linked table. (although there are wrok rounds for this)
__________________
Dave (Male!)
Gemma was my dog

if this helped, please click the scales at the top right of this posting.
Many thanks.
Reply With Quote
  #3  
Old 02-25-2010, 10:47 PM
selahlynch selahlynch is offline
Registered User
 
Join Date: Jan 2010
Location: Sultanate of Oman
Posts: 63
selahlynch is on a distinguished road
Re: does DAO.FindFirst use table indexes?

As I said before, I tried defining an index for those three fields and it did not speed up my DAO.RecordSet.FindFirst function at all. This is strange I think??

However, I tried it again using DAO.RecordSet.Seek and an appropriate index. This time it worked wonderfully. So problem solved. Thanks.
Reply With Quote
  #4  
Old 02-25-2010, 11:15 PM
selahlynch selahlynch is offline
Registered User
 
Join Date: Jan 2010
Location: Sultanate of Oman
Posts: 63
selahlynch is on a distinguished road
Re: does DAO.FindFirst use table indexes?

A snippet of code for future forum readers:

Code:
Dim db            As DAO.Database
    Dim rs            As DAO.Recordset
    
Set db = CurrentDb()
    Set rs = db.OpenRecordset("RawShot", dbOpenTable)
     
' index UniqReq(jd, sline) is defined in my access table 
rs.Index = "UniqRec"  

' ... define variables jd and sline

rs.Seek "=", jd, sline

' ... do something ...

rs.Close
Reply With Quote
  #5  
Old 02-25-2010, 11:47 PM
JANR JANR is offline
Registered User
 
Join Date: Jan 2009
Location: Norway
Posts: 712
JANR will become famous soon enough
Re: does DAO.FindFirst use table indexes?

Quote:
I tried it again using DAO.RecordSet.Seek and an appropriate index. This time it worked wonderfully.
Did you get Dave's warning:

Quote:
but seek cannot be used on a linked table. (although there are wrok rounds for this)
JR
Reply With Quote
  #6  
Old 02-26-2010, 12:18 AM
selahlynch selahlynch is offline
Registered User
 
Join Date: Jan 2010
Location: Sultanate of Oman
Posts: 63
selahlynch is on a distinguished road
Re: does DAO.FindFirst use table indexes?

Yes I did see that warning... but lucky for me, I'm not working on a linked table.

I will keep it in mind for the future though.

Thanks.
Reply With Quote
  #7  
Old 02-26-2010, 12:43 AM
DCrake's Avatar
DCrake DCrake is offline
Administrator
 
Join Date: Jun 2005
Location: Burnley, Lancashire
Posts: 6,463
DCrake is just really niceDCrake is just really niceDCrake is just really niceDCrake is just really nice
Re: does DAO.FindFirst use table indexes?

By the sound of it you are not using a linked table, this suggests that your database is not split. Even if the system is a simgle user system it is always best to have a FE/BE setup.

Because you commented on the speed - or lack of it - also suggests your are dealing with a table with a large amount of records, this is another indication that your setup is wrong.
__________________
David Crake

www.xcraftlimited.co.uk The Home of Simple Software Solutions.

O/S Windows XP (SP3) & Windows 7 64bit
Access 2003 (version 11.0)
Access 2007 (version 12.0)

Remember when posting sample databases you will get a better response if it is pre Access 2007 - not all people have it installed.
Reply With Quote
  #8  
Old 02-26-2010, 01:06 AM
selahlynch selahlynch is offline
Registered User
 
Join Date: Jan 2010
Location: Sultanate of Oman
Posts: 63
selahlynch is on a distinguished road
Re: does DAO.FindFirst use table indexes?

Well... one step at a time.

If you have any ideas about why FindFirst would not be utelizing my table indexes that would be helpful.
Reply With Quote
  #9  
Old 02-26-2010, 03:55 AM
gemma-the-husky's Avatar
gemma-the-husky gemma-the-husky is offline
AWF VIP
 
Join Date: Sep 2006
Location: UK
Posts: 7,419
gemma-the-husky is a jewel in the roughgemma-the-husky is a jewel in the roughgemma-the-husky is a jewel in the roughgemma-the-husky is a jewel in the rough
Re: does DAO.FindFirst use table indexes?

Access decides its own method for using searches - I dont think you can force it to use a particular index in find first operations, as you can with a seek method

but what are you searching - a table or a query?

if you use a query for your recordset, sorted by those 3 fields (instead of searching the table)- then it may work a lot better.

and indeed if you expect to find just a single record then design your query to just return the 1 record. Then if the rs count is 0, it wasnt found - if its 1, it was found.

there are many ways to skin this cat.
__________________
Dave (Male!)
Gemma was my dog

if this helped, please click the scales at the top right of this posting.
Many thanks.
Reply With Quote
Sponsored Links
Reply

Tags
dao, dao.findfirst, indexed field, indexes

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
need help in automatic updating database from xml pushkar1986 Modules & VBA 5 08-31-2009 07:40 PM
Automatically Adding a Record from a primary table to a secondary table VictorG Tables 5 08-24-2009 10:47 AM
In a database, how can I export record from one table to another? (w/follow-up qus) 1308057 Tables 1 07-29-2008 06:41 AM
Indexes WindSailor Theory and practice of database design 4 08-23-2006 10:30 PM
Need some suggestions on table layouts chad101 Tables 16 01-08-2006 12:01 PM


All times are GMT -8. The time now is 09:39 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
(c) copyright 2009 Access World