Solved

ADO recordset from within Access 2007

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

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…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

679 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