Solved

Data Report Error: operation is not allowed when object is closed

Posted on 2010-09-14
5
1,260 Views
Last Modified: 2013-12-25
Hi,

I am trying to populate a data report in vb6 by using an ADO recordset as the data source. I have the following text boxes on the report:

txtTicket
txtDiffference
txtStatus
txtDate

I get an error(operation is not allowed when object is closed) when the code below:

Dim rsTickets As New ADODB.Recordset
Dim dtStart As Date, dtEnd As Date

Call opnConnection

dtStart = dtpFrom.Value & " 00:00:00 AM"
dtEnd = dtpTo.Value & " 11:59:59 PM"

strSQL = "SELECT * FROM Tiko WHERE [T_Date] BETWEEN #"
strSQL = strSQL & dtStart & "# AND #"
strSQL = strSQL & dtEnd & "# ORDER BY T_Date"
Call opnRecordset(rsTickets)

With rptTickets
    Set .DataSource = rsTickets
        .DataMember = rsTickets.DataMember
    DoEvents
    .Show
End With
Call clsRecordset(rsTickets)
Call clsConnection

What is the proper sysntax for this or where am i going wrong?
0
Comment
Question by:thenemesiz
[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
  • 2
5 Comments
 
LVL 14

Expert Comment

by:Brook Braswell
ID: 33673555
What is in your opnRecordset proc?
Where are you getting your error? ( try line numbers and an error trap routine...
0
 

Author Comment

by:thenemesiz
ID: 33673676
Here are the procs:

Public Sub opnConnection()
Dim strConn As String
chkConn = connMR.State
If chkConn = adStateClosed Then
    strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strBASE & ";Persist Security Info=False"
    connMR.ConnectionString = strConn
    connMR.Open
End If
End Sub


Public Sub opnRecordset(rsOpen As Recordset)
chkRs = rsOpen.State
If chkRs = adStateClosed Then
    rsOpen.Source = strSQL
    rsOpen.CursorType = adOpenDynamic
    rsOpen.ActiveConnection = connMR
    rsOpen.Open
End If
End Sub


Public Function clsRecordset(rsClose As Recordset)
chkRs = rsClose.State
If chkRs = adStateOpen Then
    rsClose.Close
    Set rsClose = Nothing
End If
End Function

Hope that helps
0
 
LVL 14

Accepted Solution

by:
Brook Braswell earned 500 total points
ID: 33674385
Try modifying your opnRecordset in the following way....

Public Sub opnRecordSet(byRef rsOpen as Adodb.Recordset, byval SQL as string)
   dim iErr as integer
   ierr = 0
   on error goto PROC_ERR
   if rsopen.state = 1 then rsopen.close
   rsOpen.Open SQL, connMR, adOpen, adOpenDynamic

   PROC_EXIT:
      exit sub
   PROC_ERR:
      if ierr > 3 then
         ' YOUR ERROR LOGGING HERE....
     else
       ierr = ierr + 1
       resume
     endif
End Sub


The byref will ensure that you have opened the passed recordset....

0
 
LVL 53

Expert Comment

by:Dhaest
ID: 34049805
This question has been classified as abandoned and is being closed as part of the Cleanup Program.  See my comment at the end of the question for more details.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

724 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