Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

subreports and vb

Posted on 2003-03-13
19
Medium Priority
?
582 Views
Last Modified: 2012-08-13
Hi using the crystal report viewier control in VB i'm opening up crystal reports from vb without a problem however can u use subreports with this methods. i have a subreport on some of the reports and get the message saying file not found. yet they open up ok in crystal

thanks in advance
0
Comment
Question by:davoman
  • 8
  • 6
  • 4
  • +1
19 Comments
 
LVL 1

Expert Comment

by:Chess
ID: 8127815
Did you pass in the connection information to the sub-report?
0
 

Expert Comment

by:costashh
ID: 8127835
try to put the service pack from Crystal.
http://support.crystaldecisions.com/fix/hot/si75/?ref=default.asp_selectlist

They say something about the viewer.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 8129792
listening
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 

Expert Comment

by:costashh
ID: 8130020
in this PDF are many issues about subreports in viewer http://ftp.crystaldecisions.com/webprod/hot_fixes/en/ce80win_en_sp1.pdf
That's why I presume that the SP1 might resolze the issue.

(what versions of viewer/CR you are using ?)
0
 
LVL 1

Author Comment

by:davoman
ID: 8131910
I am using vb 6,0 and crystal 8.5. The subreport has its own ADO connection as is linked via a field in the main report which i am calling
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 8132704
Show the code you are using to call the reports.

mlmcc
0
 
LVL 1

Author Comment

by:davoman
ID: 8135417
Public Sub ShowReports(ByVal strquery As String, strpath As String)
On Error GoTo Error_check

Dim CRVAppl As CRAXDRT.Application
Dim CRReport As CRAXDRT.Report
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
'Set CRReport = Nothing


Set CRVAppl = New CRAXDRT.Application
Set CRReport = CRVAppl.OpenReport(strpath)
CRReport.DiscardSavedData


cn.ConnectionString = "Provider = SQLOLEDB;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;" & _
                        "Data Source=Server1;" & _
                        "Initial Catalog=FordContact"
cn.Open
rs.Open strquery, cn, adOpenKeyset

If rs.RecordCount > 0 Then
While rs.EOF = False
    CRReport.Database.SetDataSource rs
rs.MoveNext
Wend

Screen.MousePointer = vbHourglass

frmMainReports.CRViewer1.ReportSource = CRReport
frmMainReports.CRViewer1.ViewReport
frmMainReports.Show


Screen.MousePointer = vbDefault


frmMainReports.Left = (Screen.Width - frmMainReports.Width) / 2
frmMainReports.Top = (Screen.Height - frmMainReports.Height) / 2
Else
    MsgBox "There were no records to show or the report could not be created"
    Exit Sub
End If
Set CRReport = Nothing
Set CRVAppl = Nothing
Error_out:
Exit Sub

Error_check:

MsgBox "There has been and error. Please see the system administrator" & vbCr & vbCr & Err.Number & vbCr & Err.Description
Resume Error_out
End Sub
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 8136540
If rs.RecordCount > 0 Then
While rs.EOF = False
   CRReport.Database.SetDataSource rs
rs.MoveNext
Wend

What is the above code trying to do?

You only need to set the datasource once.

mlmcc
0
 
LVL 1

Author Comment

by:davoman
ID: 8193908
mm seem to have got that bit wring mimcc.

However the above code opens up the main report fine its the subreport which will not open through the view. do i also have to pass the datasource through even though it does not changed and is all linked through the main report. I have tried service pack 1 but that has made no difference

0
 
LVL 1

Author Comment

by:davoman
ID: 8193997
DOH i was just being think. Hey why not use the open sub report method!!

Cheers anyway.

Dunno who to give the points to, any advice
0
 

Expert Comment

by:costashh
ID: 8194073
Give the points to you!

I wish you the very best!
0
 
LVL 1

Author Comment

by:davoman
ID: 8194082
DOH no can do when me tells it to discard saved data i get file not found again

Has anyone got any spare hair i've just pulled mine out!!!
0
 

Expert Comment

by:costashh
ID: 8194116
Try doing separate reports!
1 report + 1 subreport = 2 separate reports!

my advice! :)
0
 
LVL 101

Accepted Solution

by:
mlmcc earned 525 total points
ID: 8195984
How are you changing the subreport?  You may have to discard saved data for the mainreport and for the subreports.

mlmcc
0
 
LVL 1

Author Comment

by:davoman
ID: 8235113
i am beggning to realise i also have to pass the date through the subreport. I though because it already had a datasource defined i would not have to do it with code
ho hum
0
 
LVL 1

Author Comment

by:davoman
ID: 8235184
Public Sub ShowSubReports(ByVal strquery As String, strpath As String, strpath1 As String)
'On Error GoTo Error_check

Dim CRVAppl As CRAXDRT.Application
Dim CRReport As CRAXDRT.Report
Dim crReportsub As CRAXDRT.Report
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Set CRReport = Nothing


Set CRVAppl = New CRAXDRT.Application
Set CRReport = CRVAppl.OpenReport(strpath)
Set crReportsub = CRReport.OpenSubreport(strpath1)
CRReport.DiscardSavedData



cn.ConnectionString = "Provider = SQLOLEDB;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;" & _
                        "Data Source=Server1;" & _
                        "Initial Catalog=FordContact"
cn.Open
rs.Open strquery, cn, adOpenKeyset

If rs.RecordCount > 0 Then
'While rs.EOF = False
    CRReport.Database.SetDataSource rs
'rs.MoveNext
'Wend
Screen.MousePointer = vbHourglass

frmMainReports.CRViewer1.ReportSource = CRReport


frmMainReports.CRViewer1.ViewReport

frmMainReports.Show


Screen.MousePointer = vbDefault


frmMainReports.Left = (Screen.Width - frmMainReports.Width) / 2
frmMainReports.Top = (Screen.Height - frmMainReports.Height) / 2
Else
    MsgBox "There were no records to show or the report could not be created"
    Exit Sub
End If
Set CRReport = Nothing
Set CRVAppl = Nothing
Error_out:
Exit Sub

Error_check:

MsgBox "There has been and error. Please see the system administrator" & vbCr & vbCr & Err.Number & vbCr & Err.Description
Resume Error_out
End Sub

ammended the code to look like this but still getting file not found
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 8235466
What are you passing for strpath1?

mlmcc
0
 
LVL 1

Author Comment

by:davoman
ID: 8235477
hotels.rpt the name of the subreport.

I've just got now it now. I needed to pass the datsource through as well and now it works at the mo. mind you i had it working before then broke it again :)
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 8279014
Glad I could help

mlmcc
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

581 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