Solved

recordset closes after executing a query

Posted on 2014-09-04
2
88 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
[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
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

726 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