Solved

ADO recordset from within Access 2007

Posted on 2008-10-17
5
2,123 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

763 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

11 Experts available now in Live!

Get 1:1 Help Now