Results 1 to 4 of 4

Thread: [RESOLVED] Operation is not allowed when the object is open.

  1. #1

    Thread Starter
    Addicted Member riechan's Avatar
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    254

    Resolved [RESOLVED] Operation is not allowed when the object is open.

    Hi guys. Can anybody help me out here? I keep getting the above error when trying to open a recordset like so:

    VBScript Code:
    1. Set connExcel = CreateObject("ADODB.Connection")
    2.     connExcel.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    3.                     "Data Source=" & Environment("API_Table") & ";" & _
    4.                     "Extended Properties=""Excel 8.0;IMEX=1;" & strHeader & """"
    5.  
    6. Set rsInputData = CreateObject("ADODB.Recordset")
    7.     rsInputData.Open "SELECT * FROM [" & strTblName & "$] WHERE Test_Case_ID ='" & strTestCaseID & "' AND " & _
    8.                     "Action='" & Environment("Action") & "'", connExcel, adOpenStatic
    9.  
    10. Set connAccess = CreateObject("ADODB.Connection")
    11. Set rsObjects = CreateObject("ADODB.Recordset")
    12.     connAccess.Provider = "Microsoft.JET.OLEDB.4.0"
    13.     connAccess.Open "C:\BFTC\Object Config\BFTC_ObjConf.mdb"
    14.  
    15. cntFields = rsInputData.Fields.Count
    16.  
    17. For ctrFields = 0 to cntFields - 1
    18.     If InStr(1, rsInputData.Fields(ctrFields).Value, "*") = 0 Then
    19.         curField = rsInputData.Fields(ctrFields).Name
    20.         curItem = rsInputData.Fields(curField).Value
    21.  
    22.         rsObjects.Open "SELECT * FROM " & strTblName & " WHERE FieldName='" & curField & "'", connAccess
    23.         If rsObjects.RecordCount > 0 Then
    24.         ...
    25.         End If
    26.         rsObjects.Close
    27.     End If
    28. Next   
    29.  
    30. rsInputData.Close
    31. connAccess.Close
    32. connExcel.Close
    33.  
    34. If rsObjects.State <> 0 Then
    35.     rsObjects.Close
    36. End If
    37.  
    38. Set rsObjects = Nothing
    39. Set rsInputData = Nothing
    40. Set connAccess = Nothing
    41. Set connExcel = Nothing

    The error occurs when I'm trying to open the second recordset, rsObjects. I was wondering if this error is caused by the first connection and recordset objects (connExcel/rsInputData) still being opened when the second recordset is opened.

    If I may also ask, if I close the rsInputData, the data from that query would be lost, right?
    ====================
    ほんとにどもありがとう!

    Rie Ishida

  2. #2
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: Operation is not allowed when the object is open.

    hav u tried with early bind?
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  3. #3

    Thread Starter
    Addicted Member riechan's Avatar
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    254

    Re: Operation is not allowed when the object is open.

    Sorry. Already fixed the problem. Admin, please delete the thread as needed. Thread resolved.
    ====================
    ほんとにどもありがとう!

    Rie Ishida

  4. #4
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: [RESOLVED] Operation is not allowed when the object is open.

    i tried this late bind method
    Code:
    Const adUseClient = 3
    Const adLockOptimistic = 3
    
    Private Sub Form_Load()
    Dim cnExcel As Object, cnAccess As Object
    Dim rsExcel As Object, rsAccess As Object
    
    Set cnExcel = CreateObject("ADODB.Connection")
    Set cnAccess = CreateObject("ADODB.Connection")
    
    Set rsExcel = CreateObject("ADODB.Recordset")
    Set rsAccess = CreateObject("ADODB.Recordset")
    
    With cnExcel
        .Provider = "Microsoft.Jet.OLEDB.4.0"
        .Properties("Extended Properties").Value = "Excel 8.0"
        .Open App.Path & "\sample.xls"
    End With
    
    With cnAccess
        .Provider = "Microsoft.Jet.OLEDB.4.0"
        .Open App.Path & "\db1.mdb"
    End With
    
    With rsExcel
        .ActiveConnection = cnExcel
        .CursorLocation = adUseClient
        .CursorType = adOpenKeyset
        .LockType = adLockOptimistic
        .Open "select * from [sample$]"
    End With
    
    With rsAccess
        .ActiveConnection = cnAccess
        .CursorLocation = adUseClient
        .CursorType = adOpenKeyset
        .LockType = adLockOptimistic
        .Open "select * from login"
    End With
    
    MsgBox rsExcel.RecordCount & "," & rsAccess.RecordCount
    End Sub
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width