Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Window placement 17 75
Access 2013 combo box not working 3 38
VB6 - Compare and highlight cell not the same 3 42
Help me. 3 45
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…
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.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

911 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

28 Experts available now in Live!

Get 1:1 Help Now