Solved

operation not allowed in this context

Posted on 2014-09-08
8
105 Views
Last Modified: 2014-09-16
I get the error "operation not allowed in this context"  Why is the error coming on line 32 when closing the recordset?



  If rec7.State = adStateOpen Then
       
                   
                  
                  
        rec7.MoveFirst
       i = 1
        Do While Not rec7.EOF
        
                  esql = "SELECT ProgressSetback, Month, Fiscal from tblOrgMonthlyProgressSetbacks where PIID = " & MSFlexGrid1.TextMatrix(i, 4) & " And MonthlyID = " & MonthlyID & " And Month = " & SelectedMonth & " And Fiscal = " & Fiscal
                        
                  rec9.CursorType = adOpenStatic
                  rec9.CursorLocation = adUseClient
                  rec9.LockType = adLockOptimistic
                  rec9.Open esql, conn, , , adCmdText
                         
                  If rec9.EOF = True And rec9.BOF = True Then
                    If MSFlexGrid1.TextMatrix(i, 10) <> "" Then
                    rec9.AddNew
                    rec9!AgencyID = AgencyID
                    rec9!PIID = MSFlexGrid1.TextMatrix(i, 10)
                    rec9!MonthlyID = MonthlyID
                    rec9!ProgressSetback = MSFlexGrid1.TextMatrix(i, 10)
                    rec9!Month = SelectedMonth
                    rec9!Fiscal = Fiscal
                    rec9.Close
                    End If
                  End If
                  
                  If rec9!ProgressSetback <> "" Then
                    rec9!ProgressSetback = MSFlexGrid1.TextMatrix(i, 10)
                    rec9.Close
                  End If
                    

                i = i + 1
        rec7.MoveNext
        Loop
        
End If
             

Open in new window

0
Comment
Question by:al4629740
  • 3
  • 2
8 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40310944
It either means you have not yet updated the recordset when adding a new record or the connection is already closed.
Is it line 32 of the code above?
0
 

Author Comment

by:al4629740
ID: 40310954
yes
0
 
LVL 58

Expert Comment

by:Gary
ID: 40310959
Add before the close line

rec9.Update
0
 

Author Comment

by:al4629740
ID: 40310985
Still does not work.  

I changed it up to this and it works now

If rec7.State = adStateOpen Then
       
                   
                  
                  
        rec7.MoveFirst
       i = 1
        Do While Not rec7.EOF
        
                  esql = "SELECT * from tblOrgMonthlyProgressSetbacks where PIID = " & MSFlexGrid1.TextMatrix(i, 4) & " And MonthlyID = " & MonthlyID & " And Month = " & SelectedMonth & " And Fiscal = " & Fiscal
                        
                  rec9.CursorType = adOpenStatic
                  rec9.CursorLocation = adUseClient
                  rec9.LockType = adLockOptimistic
                  rec9.Open esql, conn, , , adCmdText
                         
                  If rec9.EOF = True And rec9.BOF = True Then
                    If MSFlexGrid1.TextMatrix(i, 10) <> "" Then
                    rec9.AddNew
                    rec9!AgencyID = AgencyID
                    rec9!PIID = MSFlexGrid1.TextMatrix(i, 4)
                    rec9!MonthlyID = MonthlyID
                    rec9!ProgressSetback = MSFlexGrid1.TextMatrix(i, 10)
                    rec9!Month = SelectedMonth
                    rec9!Fiscal = Fiscal
                    rec9.Update
                    GoTo Process1
                    End If
                  End If
                  
                  If rec9.RecordCount > 0 Then
                    rec9!ProgressSetback = MSFlexGrid1.TextMatrix(i, 10)
                    rec9.Update
                    GoTo Process1
                  End If
Process1:
                rec9.Close
                i = i + 1
        rec7.MoveNext
        Loop
        
End If

Open in new window

0
 

Author Comment

by:al4629740
ID: 40326713
His suggestion did not fix the problem per se, but rather what I posted did.  So thats why I only gave a B
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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…

895 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

13 Experts available now in Live!

Get 1:1 Help Now