Results 1 to 3 of 3

Thread: *Resolved* Change file path of subreport at runtime

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2002
    Location
    Kansas City
    Posts
    119

    *Resolved* Change file path of subreport at runtime

    Hi! Does anyone have or know of any sample code that can change the file path of a sub report at runtime?

    Basically I have one blank Crystal Report which contains a number of subreports. I want the user to have the ability to change the order in which the reports are printed so I want to be able to assign the file path of the subreport at runtime. Is this even possible?

    Thanks in advance to anyone who can help.

    -Scott
    Last edited by slaws; Dec 8th, 2003 at 05:11 PM.
    Scott

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    I don't know of any way to change the path of an existing subreport but you might be able to get want you want by using the AddSubReportObject or ImportSubReport methods of the Section object. I think these methods may depend on your version and/or license. Sorry, no sample code - never tried them.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2002
    Location
    Kansas City
    Posts
    119
    I tried it and it worked. Thanks a lot. For anyone who would like the code here it is:
    VB Code:
    1. Dim crSection As CRAXDRT.Section
    2.     Dim crSections As CRAXDRT.Sections
    3.     Dim crObject As Object
    4.     Dim crSubReport As CRAXDRT.SubreportObject
    5.     Dim sName As String
    6.     Dim sqlReports
    7.     Dim rsReports As New ADODB.Recordset
    8.     Dim strFootIndex As String
    9.    
    10.     If db.State = adStateClosed Then db.Open strMConnect
    11.    
    12.     Set CReport = CApp.OpenReport(App.Path & "\SalarySurvey.rpt", 1)
    13.    
    14.     sqlReports = "SELECT Reports.RPT_ID, Reports.Report, Reports.PrintSeq, Reports.Print, Reports.ReportFile From Reports Where (((Reports.Print) = -1)) ORDER BY Reports.PrintSeq;"
    15.     If rsReports.State = adStateOpen Then rsReports.Close
    16.     Set rsReports = Nothing
    17.     rsReports.Open sqlReports, db, adOpenStatic, adLockOptimistic
    18.     If rsReports.RecordCount > 0 Then
    19.      rsReports.MoveFirst
    20.      'Set crSection = CReport.Sections.Item("RFa")
    21.      Do While Not rsReports.EOF
    22.       strFootIndex = Chr(96 + rsReports("PrintSeq"))
    23.       Set crSections = CReport.Areas("RF").Sections
    24.       crSections.Add "RF" & srtFootIndex
    25.       Set crSection = CReport.Sections.Item("RF" & strFootIndex)
    26.       Set crSubReport = crSection.ImportSubreport(App.Path & "\" & rsReports("ReportFile"), 0, 250)
    27.       With crSubReport
    28.        .LeftLineStyle = crLSNoLine
    29.        .RightLineStyle = crLSNoLine
    30.        .TopLineStyle = crLSNoLine
    31.        .BottomLineStyle = crLSNoLine
    32.       End With
    33.       rsReports.MoveNext
    34.      Loop
    35.     End If
    36.    
    37.     frmLabels.CRLabel.Visible = True
    38.     frmLabels.CRLabel.ReportSource = CReport
    39.     frmLabels.CRLabel.ViewReport
    40.     frmLabels.CRLabel.Zoom 75
    41.      
    42.     frmLabels.Show
    Scott

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width