[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Operation is not allowed when the object is open...VB 6

Posted on 2004-08-18
7
Medium Priority
?
1,016 Views
Last Modified: 2008-03-03
First run works fine,  The second run produces an error (3705).

    .
    .    
    rs.activeconnection = cnConn
    rs.locktype = 3                                <--- Runtime error 3705: Operation is not allowed
    rs.cursortype = 1                                                                 'when the object is open
    rs.cursorlocation = 3
    rs.Open strSQL2
    If rs.RecordCount > 0 Then
    .

----------
When it is called via:
.    
FolderIDVar = fnGetIDVal("FolderID", "tblFolder", "ItemStr", cboFolder)      '<-- this line runs fine
FileIDVar = fnGetIDValLong("FileID", "tblFile", "Folder_Id", FolderIDVar)      '<-- this line, when running fnGetIDValLong has error
.
.


Note: I open stablish the connection (cnConn) to the backend in form load event and close it/ set to nothing up on closing the form.  

Thanks,

Mike
0
Comment
Question by:Mike Eghtebas
[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
7 Comments
 
LVL 15

Expert Comment

by:SRigney
ID: 11835999
You can only set some of the properties of a recordset when it is closed.  Since you are about to re-open the recordset you should manually close it first.

rs.activeconnection = cnConn
   ' Close the recordset if it is not already closed.
   If Not rs.State = adStateClosed Then
      rs.Close
   End If
    rs.locktype = 3                                
    rs.cursortype = 1
    rs.cursorlocation = 3
    rs.Open strSQL2
    If rs.RecordCount > 0 Then
0
 

Expert Comment

by:alros
ID: 11838264
You are try to assign properties to the recordset which is open. first closed it and then assign properties and then open the recordset.

If rs.state = adstateopen then
   rs.close
end if
rs.locktype = 3
rs.cursortype=1
rs.cursorlocation=3
rs.Open sqlQuery, cnConn
If rs.RecordCount > 0 Then
...
0
 
LVL 19

Accepted Solution

by:
Shauli earned 2000 total points
ID: 11840131
Certain commands need to be set BEFORE you open a recordset. Some of them can be set WHILE you open a recordset. The cursor commands should always be set BEFORE you open a recordset, and the lock type can be set before or while you open a recordset.
Each time you open a recordset, you need to close it when you are done. Otherwise, it is left open. If a recordset is left open, and you try to set a command such as cursor location or lock type, then an error occures, again, simply because the recordset was left open.
The example below demonstrates how to open a recordset, do your stuff and close it when you are done:


    rs.CursorLocation = adUseClient  'set cursor location
    rs.Open strSQL2, cnConn, adOpenKeyset, adLockReadOnly 'open recordset and set locktype at the same time
        With rs
            If Not .EOF Then
                If .RecordCount > 0 Then
                    'do your stuff
                End If
            End If
        End With
    rs.Close    '<<<<<<<<<<<<<<< close when done

Note that if your sql statement DOES NOT contain the WHERE, then you'll have to loop through the records, and then your code would look like:

    rs.CursorLocation = adUseClient  'set cursor location
    rs.Open strSQL2, cnConn, adOpenKeyset, adLockReadOnly 'open recordset and set locktype at the same time
        With rs
            Do Until .EOF
                If .RecordCount > 0 Then
                    'do your stuff - like fill a combobox
                End If
                .MoveNext
            Loop
        End With
    rs.Close    '<<<<<<<<<<<<<<< close when done

S
0
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.

 
LVL 19

Expert Comment

by:Shauli
ID: 11840152
...Note that if your sql statement DOES NOT contain the WHERE, then you'll have to loop through the records, and then your code would look like:...
I meant if your sql statement should bring more than one result :)

S
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 11843042
Thank you for the replies,

SqlStr="Select * MyTable Where ID=" & fnIdVar(cboSomething)

Both "SqlStr" and "fnIdVar(...)" was using the same connection at the same time.  Your description helped me see that.

Note: I am opening one connection to the backend in Form Load event and set it to nothing at Query Unload.

Mike
0
 
LVL 19

Expert Comment

by:Shauli
ID: 11843261
That is the way to go, Mike. You open it upon form load, and close at QueryUnload. Glag it works for you and thanks for the points :)

S
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 11843635
Btw, this is my first VB project ever.  It is amazing how this collective conscoius (EE) heps.  You are very helpfull.

I have been doing Access for over 10 years.  When I just started it, it was very very difficult to get some answers.

Thanks

Mike
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

649 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