PC Review


Reply
Thread Tools Rate Thread

Access 2003 VBA Open Recordset

 
 
New Member
Join Date: Jun 2011
Posts: 1
 
      30th Jun 2011
Hi everyone,

I'm relatively new to VBA and definitely new to Access (2 weeks). I need some help with the following code:

Sub Repeat_ED_Visits()
Dim q1New As Object
Dim sql As String
Dim rst As ADODB.Recordset
Dim cnn As ADODB.Connection
Dim EDRepeatTbl As TableDef
With CurrentDb
sql = ("SELECT DISTINCT ...") 'my SQL query
Set q1New = .CreateQueryDef("EDRepeatQuery", sql)
End With
Set rst = New ADODB.Recordset
Set cnn = New ADODB.Connection
Set cnn = Application.CurrentProject.Connection
rst.Open sql, CurrentProject.Connection
With rst
<<code>>
End With
rst.Close
Set rst = Nothing
End Sub

When I run this, I'm getting error msg 3704 ("Operation is not allowed when the object is closed"), but my rst.Open line is there. Any ideas?

Thanks in advance,
Anh
 
Reply With Quote
 
 
 
 
Banned
Join Date: Jul 2011
Posts: 16
 
      23rd Jul 2011
Check whether the ADODB (Microsoft ActiveX Data Object n.n Library) Library File is attached to your Project or not.

  1. Open VBA Window (Alt+F11)
  2. Select References from Tools Menu.
  3. Browse for the above Library File (if it is not already selected) and put a check mark in the Dialog Control.
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
form using DAO recordset- access 2003 Winxp Microsoft Access Form Coding 5 29th May 2009 01:09 PM
How to open Access recordset via Query in Excel VBA??? Hexman Microsoft Excel Programming 4 29th Mar 2006 08:11 PM
Set Access 2003 Listbox recordset via code? kiln Microsoft Access Form Coding 9 5th Jun 2005 08:14 PM
open access recordset as an excel spreadsheet =?Utf-8?B?dG1vcnQ=?= Microsoft Access VBA Modules 21 8th Apr 2005 10:01 PM
How do I open a recordset and step through it in Access 2000 code =?Utf-8?B?UmljaCBNYXp6YQ==?= Microsoft Access VBA Modules 7 24th Feb 2004 11:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:44 PM.