Solved

ADO recordset from within Access 2007

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
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…
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…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

808 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