• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 886
  • Last Modified:

'Object was Open' error

In short I run an SQL query and produce a report based on that query. The first time I run the report it works well, however when I run it a second time without closing the form and just by changing one part of the criterion (which works fine in SQL Enterprise Manager - Query Edit Mode) e.g. Male to Female, it errors with the message 'Object was open'. I have searched google but it yields nothing sensible. I have tried a check to see if the recordset is open but it reports as closed.

code
-------
Dim BookID As Long

     With dateStats.rsResource
           .Open "select * from Resource where (AscID = '" & curASCID & "')"
            If Not .EOF Then
                     BookID = .Fields("ResourceID")
            End If
            .Close
     End With


I have also put a close statement in the terminate procedure of the data report.
0
williari
Asked:
williari
1 Solution
 
Arthur_WoodCommented:
try this change:

With dateStats.rsResource
     if .State = 1 then

           .Open "select * from Resource where (AscID = '" & curASCID & "')"
            If Not .EOF Then
                     BookID = .Fields("ResourceID")
            End If
            .Close
     End With
0
 
Arthur_WoodCommented:
oops, hit the Submit button too soon.  Let's try this one more time:

try this change:

With dateStats.rsResource
     if .State <> 0 Then   ' State = 0 is Closed, any other state must be closed, first
         .Close
     end if
           .Open "select * from Resource where (AscID = '" & curASCID & "')"
            If Not .EOF Then
                     BookID = .Fields("ResourceID")
            End If
            .Close
     End With

AW
0
 
williariAuthor Commented:
Hi AW , thanks for the response. No luck Im afraid the same message 'Object was Open' is still appearing.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
leonstrykerCommented:
williari,

You may be attempting to reopen the connection in your code without closing it.  Can you show more of your code? BTW, I would advise to get away from using ADODC.

Leon
0
 
Pi7Commented:
on which line does the error occur?
0
 
senthil_msvCommented:
With dateStats.rsResource
     if .State <> 0 Then   ' State = 0 is Closed, any other state must be closed, first
         .Close
     end if
           .Open "select * from Resource where (AscID = '" & curASCID & "')"
            If Not .EOF Then
                     BookID = .Fields("ResourceID")
            End If
            .Close
End With
set  dateStats.rsResource = nothing
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now