ADO recordset from within Access 2007

Posted on 2008-10-17
Last Modified: 2008-10-23
I am trying to load a ADO recordset from within access 2007 and just cannot get it to work.  I recieve an error "Error in Loading DLL Is this a missing reference problem?  

   Dim rs As New ADODB.Recordset
   Dim StrSQL As String
   StrSQL = "SELECT * FROM [TableName];"
   rs.Open StrSQL, CurrentProject.Connection      'or .AccessConnection same error

Can someone please provide a sample VBA code to use ADO in Access 2007.  I normally use DAO except I would like to take advantage of the recordset .Save and .Load features of ADO for one application.

Thanks in advance for any assistance you can provide.

Question by:jllabs
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
LVL 84

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 250 total points
ID: 22747644
That code should run fine. You do need a reference to the Microsoft Activex Data Objects xx, where xx is the version you want to use (generally the highest number you find on your machine).

Also, you should declare your variables as such:

Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset

Using this construct you can trap for errors and take action in the event something goes wrong when you try to set to a New object ... with your construct you'd receive a runtime error which you could not trap.

Author Comment

ID: 22748322
Sorry about that, It was almost midnight when I gave up and was a little too tired to be typing code.  The code is-

   Dim StrSQL As String
   Dim rs As ADODB.Recordset
   Set rs = New ADODB.Recordset
   StrSQL = "SELECT * FROM [TableName];"
   rs.Open StrSQL, CurrentProject.Connection   'or .AccessConnection same error

The error is generated and the program stops at at the .Connection or .AccessConnection on the last line.  The error is "Error in Loading DLL".

I have a reference set for Microsoft ActiveX Data Objects 2.8 Libary and the code will autopopulate when typing but I still recieve the error noted above.

I am not sure what I am doing wrong.   This is using VBA within the Access 2007 .accdb database and not a standalone application accessing the file
LVL 84

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 250 total points
ID: 22748351
You probably have a problem with the MDAC on your machine. You can use the Component Checker utility:

Here's a link that shows a bit more about it:

Accepted Solution

jllabs earned 0 total points
ID: 22748436
I was able to get the code to run by manually registering the Microsoft ActiveX Data Objects 2.8 Library.  

regsvr32 "c:\program files\common files\system\ado\msado15.dll"

Thanks LSMConsulting for your time and steering me in the right direction to find a solution.
LVL 84
ID: 22749260
This is not really the best way to fix MDAC issues ... you really should reinstall MDAC instead of trying to handle this on your own. MDAC is hugely complex, and different versions require dependencies to various other files and such, and there is simply no way to easily handle this manually. Glad you got this working, but I'd strong advise you to re-install MDAC ...

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

737 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