Solved

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

Posted on 2010-09-14
5
1,232 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
  • 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

776 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