Solved

operation not allowed in this context

Posted on 2014-09-08
8
102 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
Comment Utility
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
Comment Utility
yes
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
Add before the close line

rec9.Update
0
 

Author Comment

by:al4629740
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

762 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

12 Experts available now in Live!

Get 1:1 Help Now