?
Solved

operation not allowed in this context

Posted on 2014-09-08
8
Medium Priority
?
124 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
[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
  • 3
  • 2
8 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 1500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
Suggested Courses
Course of the Month11 days, 22 hours left to enroll

752 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