Link to home
Start Free TrialLog in
Avatar of kotb
kotb

asked on

Unable to access first record Error

Hi all,
I am using VB6 and Crystal Reports Component desginer 8, I want to create sub-report and I am getting this error message:

"Unable to access first record"

I am calling the report using these lines of code:

Dim RepRS As New ADODB.Recordset
RepRS.Open "Select * From Employees", MainCon, adOpenDynamic, adLockBatchOptimistic
Set varCRReport = New CrystalReport1
varCRReport.Database.SetDataSource RepRS
frmReports.CRViewer1.ReportSource = varCRReport
frmReports.Show 1

any comments?
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

change adOpenDynamic to adOpenStatic
change adLockBatchOptimistic to adLockReadOnly

be sure you also set
reprs.location = aduseclient
Avatar of kotb
kotb

ASKER

Hi emoreau, I did what you just said and still getting the same error message
show your new code
Avatar of kotb

ASKER

Dim RepRS As New ADODB.Recordset
RepRS.CursorLocation = adUseClient
RepRS.Open "Select * From Employees", MainCon, adOpenStatic, adLockReadOnly
Set varCRReport = New CrystalReport1
varCRReport.Database.SetDataSource RepRS
frmReports.CRViewer1.ReportSource = varCRReport
frmReports.Show 1
Is your recordset empty?
Avatar of kotb

ASKER

mayankeagle, It didn't help, I registred the dll and the report is still giving me the same error message.

emoreau,
My recordset is not empty, its giving 76 records
Avatar of kotb

ASKER

hi s_sansanwal,
actually I read this articel before and i was trying to implement it this way:
Dim RepRS As New ADODB.Recordset, RepRS1 as New ADODB.Recordset
RepRS.CursorLocation = adUseClient
RepRS.Open "Select * From Employees", MainCon, adOpenStatic, adLockReadOnly
RepRS1.CursorLocation = adUseClient
RepRS1.CursorType = adOpenDynamic

Set RepRS1 = RepRS.Clone    'And it gives me error here "Object or provider is not capable of performing requested operation"

Set varCRReport = New CrystalReport1
varCRReport.Database.SetDataSource RepRS
frmReports.CRViewer1.ReportSource = varCRReport
frmReports.Show 1

Avatar of kotb

ASKER

OK, I got the error, I had to change
RepRS.Open "Select * From Employees", MainCon, adOpenDynamic, adLockReadOnly

To

RepRS.Open "Select * From Employees", MainCon, adOpenStatic, adLockReadOnly

The recordset is clonning now but still when the report opens gives me "File Not Found", What kind of crazy crystal
Why are you cloning your recordset? Remove everything related to RepRS1
Avatar of kotb

ASKER

I am cloning the recordset because of the article sent by  s_sansanwal
Have you tried removing everything related to the clone recordset.
Avatar of kotb

ASKER

I did and I get "Unable to access first record"
>> I am cloning the recordset because of the article sent by  s_sansanwal

Don't clone it just if the article does so. It might be doing that for something else. Just use those parts from the article which you need. Can we have your latest code?
Avatar of kotb

ASKER

Ok, The first message disappeared and my latest code is:

Dim RepRS As New ADODB.Recordset
RepRS.Open "Select * From [Tapes] Where MediaID = 'P043420'", MainCon, adOpenStatic, adLockReadOnly
Set varCRReport = New CrystalReport1
varCRReport.Database.SetDataSource RepRS
frmReports.CRViewer1.ReportSource = varCRReport
frmReports.Show 1

But  I am still getting "File Not Found" Error Message and nothing comes after that "Blank Page"


Avatar of kotb

ASKER

I forgot to say that The last post is for Crystal Report based on SQL-Server connection, the other posts for Access Database
Where is your cursorlocation set?

RepRS.CursorLocation = adUseClient
Where is the crystal-report file?
Avatar of kotb

ASKER

My latest code:
Dim RepRS As New ADODB.Recordset
RepRS.CursorLocation = adUseClient
RepRS.Open "Select * From [Tapes] Where MediaID = 'P043420'", MainCon, adOpenStatic, adLockReadOnly
Set varCRReport = New CrystalReport1
varCRReport.Database.SetDataSource RepRS
frmReports.CRViewer1.ReportSource = varCRReport
frmReports.Show 1

The Crystal Report main file is CrystalReport1 and its in the same project directory, The sub-report is embedded in the main report and has no separate file, could any one please make a small example and send it to my email: qutb@hotmail.com
Thanks a lot
You shouldn't post e-mail IDs on question-pages. Did you try setting RepRS.CursorLocation = adUseClient after the RepRS.Open statement?
Avatar of kotb

ASKER

I didnt know about email ID, I will try now
mayankeagle ,

>>Did you try setting RepRS.CursorLocation = adUseClient after the RepRS.Open statement

The CursorLocation has to be set before opening the recordset.
>>The sub-report is embedded in the main report and has no separate file

Where are you setting the sub-report datasource?
Avatar of kotb

ASKER

>>Did you try setting RepRS.CursorLocation = adUseClient after the RepRS.Open statement
I am doing so


>> Where are you setting the sub-report datasource?
inside the sub-report itself "ado"
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kotb

ASKER

want to thank emoreau, the problem almost solved with the last link you sent , I just need to try in different patterns.
I can say that the problem was first in the recordset type then we had to pass the recordset "database" to the embedded sub-report

My final code is:

strMainCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\SubReport\db1.mdb;Persist Security Info=False"
On Error Resume Next
MainCon.Close
MainCon.ConnectionString = strMainCon
MainCon.Open
Dim rs As New ADODB.Recordset

Dim RepRS As New ADODB.Recordset
RepRS.CursorLocation = adUseClient
RepRS.CursorType = adOpenDynamic
RepRS.Open "Select * From [Tapes] Where MediaID = 'P035791'", MainCon, adOpenDynamic, adLockReadOnly

rs.CursorLocation = adUseClient
rs.CursorType = adOpenDynamic
rs.Open "Select * From ShotListing Where MediaID = 'P035791'", MainCon, adOpenDynamic, adLockReadOnly

Set varCRReport = New CrystalReport1
varCRReport.Database.SetDataSource RepRS

For Each sect In varCRReport.Sections
    For Each rptObject In sect.ReportObjects
        If rptObject.Kind = crSubreportObject Then
            Set subReport = rptObject
                'If subReport.Name = "Details" Then
                    subReport.OpenSubreport.Database.SetDataSource rs, 3
                'End If
            Set subReport = Nothing
        End If
    Next
Next


frmReports.CRViewer1.ReportSource = varCRReport
frmReports.Show 1

Avatar of kotb

ASKER

Its working great now, the problem was:

1. Changing the cursor location to adUseClient and the cursor type to be adOpenDynamic
2. Passing the database "Recordset object" to the sub-report

Thanks alot guys
Glad to know you solved it.

>> The CursorLocation has to be set before opening the recordset.

Duh~! I guess you're right. Its been ages since I worked with VB6. Am more into Java/ J2EE and some bit of .NET.