Re: Application-defined or object-defined error

alicejwz

Registered User.
Local time
Today, 08:29
Joined
Jul 9, 2003
Messages
91
Re: Application-defined or object-defined error

:mad: Good Morning,

I am trying to set my report's recordsource by using the code below in the report open event but it is giving me this error message:
Ms VB
Runtime error 2465
Application-defined or object-defined error

The same code is used in open form event and works fine.
Any help would be appreciated.

Private Sub Report_Open(Cancel As Integer)
str = "Select * from tblShipping_sched"
Set rst = New ADODB.Recordset
rst.CursorLocation = adUseServer
rst.Open str, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
Set Reports("rptSampling_sched").Recordset = rst
 
You have to set a referenec to ADO from the References Dialog.

Open a module, goto Tools -> References and then activate ActiveX Data Objects.
 
RE:Application-defined or object-defined error

Thanks for your reply.
I have MS ActiveX Data Objects 2.1 Library checked in Reference Library.
This code works in the form open event. is it because it is a report?
This code the similiar code for the form open event:
sqlstr = "Select * From tblShipment_history where " & filterstr
Set rstShipment_history = New ADODB.Recordset
rstShipment_history.CursorLocation = adUseServer
'Debug.Print sqlstr
rstShipment_history.Open sqlstr, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
Set Forms("shipment_history_list").Recordset

Thanks!
 
Unless you are not using Option Explicit you will also need to Dim an ADODB.Recordset
 
Hi SJ,

Thanks for your reply.
I have the following in my code:
Option Compare Database
Option Explicit

Private Sub Report_Open(Cancel As Integer)
Dim str As String, dt As Date, dte As Date
Dim rst As New ADODB.Recordset
:
Could this be problem using report object.

I'm using AC2K and Sql Server 2000.
Thanks!
 
alicejwz said:
Could this be problem using report object?

I don't know. Never used SQL Server and rarely use ADO.

I can tell you, though, that Dim str As String is dodgy. str is the name of a function and is therefore reserved. You should give your variables more appropriate names - that way, in future, you will understand what you were doing.
 

Users who are viewing this thread

Back
Top Bottom