Solved

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

Posted on 2010-09-14
5
1,219 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now