Solved

how to close a recordset really?

Posted on 2000-04-28
5
159 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
5 Comments
 
LVL 3

Accepted Solution

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

Expert Comment

by:Sage020999
Comment Utility
set RSm = nothing
0
 
LVL 6

Expert Comment

by:Marine
Comment Utility
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
Comment Utility
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
Comment Utility
You are using recursion, which is not good for cleanup of your variables.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now