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.SetDa taSource RepRS
frmReports.CRViewer1.Repor tSource = varCRReport
frmReports.Show 1
any comments?
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.SetDa
frmReports.CRViewer1.Repor
frmReports.Show 1
any comments?
ASKER
Hi emoreau, I did what you just said and still getting the same error message
show your new code
ASKER
Dim RepRS As New ADODB.Recordset
RepRS.CursorLocation = adUseClient
RepRS.Open "Select * From Employees", MainCon, adOpenStatic, adLockReadOnly
Set varCRReport = New CrystalReport1
varCRReport.Database.SetDa taSource RepRS
frmReports.CRViewer1.Repor tSource = varCRReport
frmReports.Show 1
RepRS.CursorLocation = adUseClient
RepRS.Open "Select * From Employees", MainCon, adOpenStatic, adLockReadOnly
Set varCRReport = New CrystalReport1
varCRReport.Database.SetDa
frmReports.CRViewer1.Repor
frmReports.Show 1
Is your recordset empty?
See if this helps:
http://www.shortcuts.com.au/community/kb/detail.asp?iFaq=312&iType=24 (download the document).
http://www.shortcuts.com.au/community/kb/detail.asp?iFaq=312&iType=24 (download the document).
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
emoreau,
My recordset is not empty, its giving 76 records
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.SetDa taSource RepRS
frmReports.CRViewer1.Repor tSource = varCRReport
frmReports.Show 1
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.SetDa
frmReports.CRViewer1.Repor
frmReports.Show 1
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
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
ASKER
I am cloning the recordset because of the article sent by s_sansanwal
Have you tried removing everything related to the clone recordset.
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?
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?
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.SetDa taSource RepRS
frmReports.CRViewer1.Repor tSource = varCRReport
frmReports.Show 1
But I am still getting "File Not Found" Error Message and nothing comes after that "Blank Page"
Dim RepRS As New ADODB.Recordset
RepRS.Open "Select * From [Tapes] Where MediaID = 'P043420'", MainCon, adOpenStatic, adLockReadOnly
Set varCRReport = New CrystalReport1
varCRReport.Database.SetDa
frmReports.CRViewer1.Repor
frmReports.Show 1
But I am still getting "File Not Found" Error Message and nothing comes after that "Blank Page"
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
RepRS.CursorLocation = adUseClient
Where is the crystal-report file?
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.SetDa taSource RepRS
frmReports.CRViewer1.Repor tSource = 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
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.SetDa
frmReports.CRViewer1.Repor
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?
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.
>>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?
Where are you setting the sub-report datasource?
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"
I am doing so
>> Where are you setting the sub-report datasource?
inside the sub-report itself "ado"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.OL EDB.4.0;Da ta Source=C:\SubReport\db1.md b;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.SetDa taSource 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.Da tabase.Set DataSource rs, 3
'End If
Set subReport = Nothing
End If
Next
Next
frmReports.CRViewer1.Repor tSource = varCRReport
frmReports.Show 1
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.OL
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.SetDa
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.Da
'End If
Set subReport = Nothing
End If
Next
Next
frmReports.CRViewer1.Repor
frmReports.Show 1
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
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.
>> 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.
change adLockBatchOptimistic to adLockReadOnly
be sure you also set
reprs.location = aduseclient