Solved

ADO recordset from within Access 2007

Posted on 2008-10-17
5
2,129 Views
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.


0
Comment
Question by:jllabs
  • 3
  • 2
5 Comments
 
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.
0
 

Author Comment

by:jllabs
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 VB.net application accessing the file
0
 
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:

http://www.microsoft.com/downloads/details.aspx?FamilyId=8F0A8DF6-4A21-4B43-BF53-14332EF092C9&displaylang=en

Here's a link that shows a bit more about it:
http://support.microsoft.com/kb/301202
0
 

Accepted Solution

by:
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.
0
 
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 ...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of utilizing SQL Server views 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 Microsoft Access…

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now