?
Solved

Access 2007 - Lifetime of an ADODB recordset

Posted on 2009-02-08
3
Medium Priority
?
374 Views
Last Modified: 2012-05-06
The following function executes a stored procedure which returns a recordset.
After the "End With" statement the immediate window shows g_rstFindCall.EOF as FALSE.
After the CloseConnection method executes the immediate window considers the g_rstFindCall is Closed, even though there is no explicit code to do this.   How can I extend the lifetime of the record set after the connection to the database has closed?
No where do I do an Set g_rstFindCall = New ADODB.Recordset as I think the
Set g_rstFindCall = .Execute    'retrieve the recordset
statement is doing this.

Thanks in advance

Dim g_rstFindCall As ADODB.Recordset
 
Private Function GetFollowupsRecordSet() As Boolean
    On Error GoTo ErrorHandler
    
    Dim prm1 As ADODB.Parameter
    
    ' Clean up the last record set
    Set g_rstFindCall = Nothing
    
    If (Not ConnectToSQLServer("GetFollowupsRecordSet")) Then
        GetFollowupsRecordSet = False
        Exit Function
    End If
    
    With g_adoCmd
        .CommandText = "GetFollowups"
        .CommandType = adCmdStoredProc
        Set prm1 = .CreateParameter("@lAgentID", adInteger, adParamInput)
        .Parameters.Append prm1
        .Parameters("@lAgentID").Value = g_lUserID ' input value
        Set g_rstFindCall = .Execute    'retrieve the recordset
    End With
    GetFollowupsRecordSet = True
    
GetFollowupsRecordSet_Click:
    CloseConnection
    Exit Function
        
ErrorHandler:
    Dim results
    results = MsgBox("Error encountered while getting followup information!" & vbCrLf _
                     & "Unexpected error - Error #" & Err.Number & " Description: " & Err.Description & " in method 'GetFollowupsRecordSet'", vbCritical)
    GetFollowupsRecordSet = False
    Resume GetFollowupsRecordSet_Click
 
End Function
 
 
Public Sub CloseConnection()
    ' Close the connection that was opened in ConnectToSQLServer
 
    If (g_adoCon.State = adStateOpen) Then
        g_adoCon.Close
        Set g_adoCmd = Nothing
    End If
 
End Sub

Open in new window

0
Comment
Question by:SheahaST
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
kmslogic earned 2000 total points
ID: 23587289
Use .getrows to copy the contents of your recordset to an array before you close it.  
0
 

Author Comment

by:SheahaST
ID: 23596103
Thanks,  I wasn't familar with .getrows.   So closing the connection to the database implicitly closes the recordset?
0
 
LVL 16

Expert Comment

by:kmslogic
ID: 23596137
Yes, there's no way around that.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses

839 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