22

This is not a question about which is better, but rather a question regarding why they differ functionally. The problem I was running into has been handled, but I am curious as to why this behavior is happening.

Background - using Excel vba to pull data from an Access database. When user clicks a button, a recordset is pulled from Access, and it populates various data to the spreadsheet. Then, another recordset is pulled from a different query to populate another part of the spreadsheet.

What ADO does - ADO works great for my first recordset. However, my second recordset goes to the query in Access, runs, and returns no rows. If I run this query in Access, it does open up (after about 3 to 4 seconds). This query has multiple joins, computed items, limits, and possibly Union queries (I tried it many different ways, with/without union,etc.). I tried closing and reopening the ado connection. I tried changing timeout values, and I even tested using an ADO command to run Make table queries for this data, and then pull from the table instead (this worked by the way, but is not the best-case, since the data changes continually, and I do not want to have to run the make table query everytime someone uses this tool).

So, I changed the second data pull to DAO, and lo and behold, it works. The first data pull is still ADO (which I generally prefer to use), but am now considering changing it to DAO, because I would rather have one data access method in the code.

So, can someone explain to me why ADO will not pull the data in one case, but DAO will? Again, this is purely for informational purposes.

4
  • 1
    It's difficult to comment without seeing your code, but it may be a cusrsor type/recordset type issue. Are you relying on defaults in your code? If you are only working with Access, DAO is a better choice as it is native to Access and gives more control than ADO
    – SWa
    Mar 16, 2012 at 12:31
  • 2
    Where you using wildcards? This is a common problem, for ADO the wildcard is %, whereas DAO is (usually) *.
    – Fionnuala
    Mar 16, 2012 at 13:49
  • @Remou, I am familiar with the difference in wildcard between the two, but I unfortunately do not use them in the queries.
    – APrough
    Mar 16, 2012 at 14:33
  • @Kyle, cursortype is adClient, recordset is adDynamic and asLockOptimistic (not completely sure, code is not in front of me). I use a standard routine to set all of my recordsets, so all queries go through it. First ran, second didn't, change to pull from table and it worked. So cursor/recordset issues probably not the issue.
    – APrough
    Mar 16, 2012 at 14:36

3 Answers 3

15

DAO is the native data access method for the Jet (Ms-Access) data tables. ADO "Active X Data Objects" is an industry friendly connection to almost all types of database.

With a standard query there is no reason in this case why ADO should return no records where DAO does, I suspect it's that the query must also contain parameters relating to items within the Access database. If this is the case then ADO will not work as it will not have the option of using said parameters as it is just an external reference to Excel, using the DAO method will trigger Access to run the query rather than Excel and as such it will be able to access it's own parameters/references.

3
  • @Matt Donnan - Parameters should not be an issue; both of the queries use them, and after I changed it to a table, it still used them. There has to be something else where the query process is taking too long or something. However, I like your comment "using the DAO method will trigger Access to run the query rather than Excel and as such it will be able to access it's own parameters/references". Maybe ADO is having Excel try to process the query and it is getting lost there?
    – APrough
    Mar 16, 2012 at 14:39
  • @creamyegg and Kyle. I agree that DAO is probably the better choice, but I generally use ADO against SQL Server, plus my habits die hard, and using ADO most of the time is fine until I run into an issue like this :P Oh well, need to ingrain myself to use DAO from now on (in these types of projects).
    – APrough
    Mar 16, 2012 at 14:45
  • 2
    @APrough Yep, to confirm, ADO will be having Excel run the query with Access just as the data source, whereas DAO will have Access run the query and return the data to Excel. As some have mentioned DAO is best for Access with ADO being the choice for dedicated servers such as MS SQL, Oracle, MySQL etc. Mar 16, 2012 at 16:51
6

I think this question was answered very well already but I want to add another excellent (although somewhat hard to find) resource for comparing DAO and ADO. It's targeted primarily at Access applications with Access forms and reports, but much of the information here would apply to a solution written in Excel.

UtterAccess Wiki Article: Choosing between ADO and ADO

1
4

In Visual Basic, three data access interfaces are available to you: ActiveX Data Objects (ADO), Remote Data Objects (RDO), and Data Access Objects (DAO). A data access interface is an object model that represents various facets of accessing data. Using Visual Basic, you can programmatically control the connection, statement builders, and returned data for use in any application.

Why are there three data access interfaces in Visual Basic? Data access technology is constantly evolving, and each of the three interfaces represent a different state of the art. The latest is ADO, which features a simpler — yet more flexible — object model than either RDO or DAO. For new projects, you should use ADO as your data access interface.

1
  • So ADO is more modern than DAO.
    – Timo
    Aug 14, 2020 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.