Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2010-09-14
5
Medium Priority
?
1,287 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…
Suggested Courses

636 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