Solved

recordset closes after executing a query

Posted on 2014-09-04
2
86 Views
Last Modified: 2014-09-04
In the following code sequence, I have a problem.  After line 11 is executed, it closes the recordset and then when the sequence is looped, I get the error...operation not allowed when the object is closed.

Any ideas why its closing?

If rec.State = adStateOpen Then
        
       rec.MoveFirst
       i = 1
        Do While Not rec.EOF
        
                If IsNull(rec!ProgressSetback) Then
                    If MSFlexGrid1.TextMatrix(i, 9) <> "" Then
                    sStringtoEx = "insert into tblOrgMonthlyProgressSetbacks (PIID, monthlyid, agencyid, progresssetback) values " & _
                    "(" & MSFlexGrid1.TextMatrix(i, 4) & "," & MonthlyID & "," & AgencyID & ",'" & MSFlexGrid1.TextMatrix(i, 9) & "')"
                    Set rec = conn.Execute(sStringtoEx)
                    End If
                End If
                
                If rec!ProgressSetback <> "" Then
                    If MSFlexGrid1.TextMatrix(i, 9) <> "" Then
                    sStringtoEx = "update tblOrgMonthlyProgressSetbacks set progresssetback= '" & MSFlexGrid1.TextMatrix(i, 9) & "' where PIID = " & MSFlexGrid1.TextMatrix(i, 4) & ""
                    Set rec = conn.Execute(sStringtoEx)
                    End If
                End If
                i = i + 1
                rec.MoveNext
   
        Loop
End If

Open in new window

0
Comment
Question by:al4629740
2 Comments
 
LVL 25

Accepted Solution

by:
SStory earned 500 total points
ID: 40304755
Seems to me that you are looping through rec.
But then you blow away rec by doing an insert at line 11.

How can you loop through the thing you are blowing away by executing a new query, storing the result in rec --thus a totally different object--and hope to still loop the original. The variable reference has changed?
Why wouldn't you set rec2=conn.execute...?

Or am I missing something?
0
 

Author Comment

by:al4629740
ID: 40304809
I totally missed that.  Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need VBS version of Excel date conversion 4 65
Paint/Redraw window while dragging 16 68
using web browser with BING 40 111
VB6 ListBox Question 4 34
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

864 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

21 Experts available now in Live!

Get 1:1 Help Now