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
Solved

how to close a recordset really?

Posted on 2000-04-28
5
161 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
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
Excel VBA combine two working workbooks 8 60
How to debug this code 7 64
VB6 - Compare and highlight cell not the same 3 53
checkbox to hide entire section 10 42
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…

829 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