Solved

how to close a recordset really?

Posted on 2000-04-28
5
162 Views
Last Modified: 2010-05-02
as follow:
*************************************
Function rhigh(maxdate As Date, Edate As Date, stockID As String, n As Integer, resultvalue As Integer, eachfield As String, resultfield As String)
Dim RSm As ADODB.Recordset
Dim str
Dim rmaxdate As Date
Set RSm = New ADODB.Recordset
str = "select count(*) as sum ,max(" & eachfield & ") as max ,stockID from " & stockID & " where tdate>#" & maxdate & "# and tdate<#" & Edate & "# group by stockID"
    Set RSm = stockDB.Execute(str)
    If Not RSm.EOF Then
    If RSm("sum") > n Then
        str = "select tdate from " & stockID & " where tdate>#" & maxdate & "# and tdate<#" & Edate & "# and " & eachfield & "=" & RSm("max") & " order by tdate"
        RSm.Close
        RSm.Open str, stockDB, adOpenStatic
        If Not RSm.EOF Then
            rmaxdate = RSm("tdate")
            RSm.Close
            str = "select count(*) as count from " & stockID & " where tdate<#" & rmaxdate & "# and tdate>#" & maxdate & "#"
            RSm.Open str, stockDB
            If RSm("count") >= n Then
                str = "update resulthis set " & resultfield & "='" & resultvalue & "' where stockID ='" & stockID & "' and tdate=#" & rmaxdate & "#"
                stockDB.Execute str
                lhigh maxdate, rmaxdate, stockID, n, resultvalue, eachfield, resultfield
            End If
            rhigh rmaxdate, Edate, stockID, n, resultvalue, eachfield, resultfield
        End If
    End If
    End If
    RSm.Close
End If
End Function

Function newlhigh(maxdate As Date, Edate As Date, stockID As String, n As Integer, resultvalue As Integer, eachfield As String, resultfield As String)
Dim RSm As ADODB.Recordset
Dim str, rmaxdate
Set RSm = New ADODB.Recordset
If maxdate < Edate And Edate > startdate Then
        str = "select max(" & eachfield & ") as max ,stockID from " & stockID & " where tdate>#" & maxdate & "# and tdate<#" & Edate & "# group by stockID"
        Set RSm = stockDB.Execute(str)
        str = "select tdate from " & stockID & " where tdate>#" & maxdate & "# and tdate<#" & Edate & "# and " & eachfield & "=" & RSm("max") & " order by tdate"
        RSm.Close
        RSm.Open str, stockDB, adOpenStatic
        If Not RSm.EOF Then
            str = "update resulthis set " & resultfield & "='" & resultvalue & "' where stockID ='" & stockID & "' and tdate=#" & RSm("tdate") & "#"
            stockDB.Execute str
            newlhigh maxdate, RSm("tdate"), stockID, n, resultvalue, eachfield, resultfield
            rhigh RSm("tdate"), Edate, stockID, n, resultvalue, eachfield, resultfield
        End If
        RSm.Close
End If
End Function

Function lhigh(maxdate As Date, Edate As Date, stockID As String, n As Integer, resultvalue As Integer, eachfield As String, resultfield As String)
Dim RSm As ADODB.Recordset
Dim str, rmaxdate
Set RSm = New ADODB.Recordset
If maxdate < Edate And Edate > startdate Then
    str = "select count(*) as sum ,max(" & eachfield & ") as max ,stockID from " & stockID & " where tdate>#" & maxdate & "# and tdate<#" & Edate & "# group by stockID"
    Set RSm = stockDB.Execute(str)
    If Not RSm.EOF Then
    If RSm("sum") > n Then
        str = "select tdate from " & stockID & " where tdate>#" & maxdate & "# and tdate<#" & Edate & "# and " & eachfield & "=" & RSm("max") & " order by tdate"
        RSm.Close
        RSm.Open str, stockDB, adOpenStatic
        If Not RSm.EOF Then
            str = "update resulthis set " & resultfield & "='" & resultvalue & "' where stockID ='" & stockID & "' and tdate=#" & RSm("tdate") & "#"
            stockDB.Execute str
            lhigh maxdate, RSm("tdate"), stockID, n, resultvalue, eachfield, resultfield
            rhigh RSm("tdate"), Edate, stockID, n, resultvalue, eachfield, resultfield
        End If
    End If
    End If
    RSm.Close
End If
End Function
**************************************
errors appears:
runtime error(80004005),cannot open a table again.

please tell me why to open many table but not to close them really?
how to do ?

0
Comment
Question by:senucarthur
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 3

Accepted Solution

by:
myqlG earned 50 total points
ID: 2760366
rs.close
set rs = nothing
0
 
LVL 2

Expert Comment

by:Sage020999
ID: 2760368
set RSm = nothing
0
 
LVL 6

Expert Comment

by:Marine
ID: 2760371
To properly close recordset is to first close it by using .Close Method and then to Set it to Nothing therefore releasing it from memory. You can use more then one recordset which will point to other tables.
0
 
LVL 6

Expert Comment

by:Marine
ID: 2760390
you using connection alot and executing Update statements on it which is great, but if you don't want it to return recordset do it like this.

stockDB.Execute str,,adExecuteNoRecords
Because behind the sence ADO builds a recordset for you, this won't cause you problems but it might be faster for your application to run.
               
0
 
LVL 15

Expert Comment

by:ameba
ID: 2761087
You are using recursion, which is not good for cleanup of your variables.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

740 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