473,779 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error message, operation not allowed when object is closed

1 New Member
Hi,

I am getting an error "operation not allowed when object is closed" when executing the following code. I am getting the runtime error at
While Recordset.EOF <> True

I am not sure where the problem is.
Plz let me know if you have idea on it.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim query As String
  3. Dim RunNum As Integer
  4. Dim rng As Range
  5.  
  6. Sub getdata()
  7.  
  8.     CLRPercent = " pr_selectpercent RUN#, 1080, 0"
  9.     RuNnum = Split(InputBox("Enter your run numbers as  comma delimated values "), ",")
  10.   Set ws = Application.ActiveWorkbook.Sheets.Item("Summary")
  11.   For I = 0 To 4
  12.      Select Case I
  13.  
  14.     Case 0
  15.     Case 1
  16.  
  17.     Case 2
  18.  
  19.  
  20.         For Each Cell In [B27:Z27]
  21.         Cell.ClearContents
  22.         Next
  23.         query = CLRPercent
  24.         Myrow = 27
  25.         MyCol = 2
  26.         GetPB1C MyCol, Myrow, RuNnum, query
  27.  
  28.     Case 4
  29.  
  30.   End Select
  31. Next
  32.  
  33. End Sub
  34.  
  35. Sub GetPB1C(MyCol, Myrow, RuNnum, query)
  36.  
  37. For RunNumIndex = 0 To UBound(RuNnum)
  38.        DefaultConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=True;User ID=a;Password = r ;Data Source= sab;Use Encryption for Data=False;Initial Catalog=AutomatedQA"
  39.        Set Connection = CreateObject("ADODB.connection")
  40.        Set Recordset = CreateObject("ADODB.Recordset")
  41.        Connection.ConnectionString = DefaultConnectionString
  42.        Connection.Open
  43.        query = Replace(query, "RUN#", RuNnum(RunNumIndex))
  44.        Set ws = Application.ActiveWorkbook.Sheets.Item("Summary")
  45.        Recordset.Open query, Connection
  46.        Ow = Application.ThisWorkbook.Name
  47.  
  48.      While Recordset.EOF <> True
  49.         If Recordset.EOF <> True Then
  50.           ws.Cells(Myrow, MyCol) = Recordset.Fields("percentage").Value
  51.  
  52.         End If
  53.         Recordset.Movenext
  54.      Wend
  55.      MyCol = MyCol + 1
  56.    Next
  57.  
  58.  End Sub
  59.  
the query retuns a value in SQL Server with column name percentage and value 0.49
pr_selectpercen t 5, 1080, 0


the Procedure is :

Expand|Select|Wrap|Line Numbers
  1. USE [AutomatedQA]
  2. GO
  3. SET ANSI_NULLS ON
  4. GO
  5. SET QUOTED_IDENTIFIER ON
  6. GO
  7.  
  8. ALTER PROCEDURE [dbo].[pr_selectpercent] @runID int , @pid int ,@PVALUE int
  9. As
  10. Begin 
  11.  
  12. DECLARE @COUNTPERCENT numeric(10,2)
  13. DECLARE @MATCH int
  14. DECLARE @TOTAL int
  15. DECLARE @MATCHNUM numeric(10,2)
  16. DECLARE @TOTALNUM numeric(10,2)
  17.  
  18. select @MATCH=COUNT(perfmonvalue) from Run_Perfmon_details where runid =@runID and perfmonid = @perfmonid AND PERFMONVALUE > @PERFMONVALUE
  19.  
  20.  
  21. select @TOTAL=COUNT(perfmonvalue) from Run_Perfmon_details where runid =@runID and perfmonid = @perfmonid
  22.  
  23. select @MATCHNUM = convert(numeric (10, 2),@MATCH)
  24. select @TOTALNUM = convert(numeric (10, 2),@TOTAL)
  25.  
  26. SET @COUNTPERCENT = @MATCHNUM*100/@TOTALNUM 
  27.  
  28. SELECT @COUNTPERCENT as percentage
  29.  
  30. end
  31.  
  32.  
Dec 8 '10 #1
1 2487
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Your Recordset.Open statement at line 45 is clearly failing to open the recordset concerned - hence the error message about the object being closed. I cannot comment on why this is so - you'll need to set breakpoints in your routine and step through the code a line at a time to work this one out.

I would also advise that you are continually opening new connections in your FOR loop without closing the previous one at the end of the loop. You should always explicitly close such a connection before re-opening it.

-Stewart
Dec 9 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4862
by: cliverama | last post by:
help! fried brains.... asp calling a sqlserver7 stored proc which dynamically builds a sqlstatement & passes it to sp_executesql asp page gives the operation not allowed when object is closed error this is the asp code: Set connInc= server.CreateObject("ADODB.Connection") connInc.Open "DSN=db_database;User ID=userid;Password=xxxxxx" Set rsInc= server.CreateObject("ADODB.Recordset")
8
4066
by: Steve | last post by:
I have several pairs of synchronized subforms in an application. I have a Delete button for each pair that uses the following code or similar to delete a record in the second subform: DoCmd.SetWarnings False DoCmd.RunCommand acCmdDeleteRecord DoCmd.SetWarnings True End If ExitHere: Me!SubName.SetFocus
1
4237
by: hrhoe | last post by:
Hi, I'm trying to create a reusable component with C#. So, I created a user control that uses Microsoft SQLDMO Object Library (SQLDMO). And I could add that UserControl on Toolbox. However, whenever I'm trying to add this user control on the client program's form I'm getting the following error message. ----------------------
1
2694
by: amitbadgi | last post by:
Hello guys I am getting this error while converting an asp applicayion to asp.net Exception Details: System.Runtime.InteropServices.COMException: Operation is not allowed when the object is closed. Source Error: Line 168: rs = Server.CreateObject("ADODB.recordset")Line 169:
1
4022
by: Matt | last post by:
Got this problem that killing me...what am i doing wrong with this old dll. When i call the function from asp i get "Operation is not allowed when object is closed" any clue will be appriciated.... test .asp <% dim oObj dim a set oObj= server.CreateObject("MyDll.MyClass")
1
2142
by: jigu | last post by:
<html> <head><title>testing connection asp to mdb</title></head> <body> <% dim sql_insert,sSQL src = "C:\websites1\yourdominname\mydatabase.mdb" sConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & src ' Uncomment the next two lines and comment the above line to switch between Access and SQL. Set OBJdbConn = Server.CreateObject("ADODB.Connection") Set rs = Server.CreateObject("ADODB.Recordset")
1
1371
by: ramyamuthusamy | last post by:
hi, I installed a new software called magic folders.. Also i reinstalled it few days back. After the reinstallation an error message occcurs that"windows cannot find magic.exe go to search and search it" and i did the same. i found the file and deleted. But the error message is appearing still.. Also it reduce the speed of the system.. i don't know what to do...
2
2676
by: sailor152 | last post by:
I am having the following error when I try to access a remote DB on remote server from my MS SQL 2005 Studio Express Anyone can explain why I have the following error ------------------------------------------------------------------------------------------------------ TITLE: Microsoft SQL Server Management Studio Express ------------------------------ Failed to retrieve data for this request. (Microsoft.SqlServer.Express.SmoEnum)
1
2479
by: govind161986 | last post by:
Dear All, I have a stored procedure in which I have used a temporary table which selects the value from two tables and display the result. When I run the stored procedure from Sql's query analyzer window the stored procedure runs fine and also retrieves the record but when I execute the same procedure from aspx page it retrives an error message "Operation is not allowed, when the object is closed" it doesn't retrives the records. Thanks. ...
0
9636
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9930
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.