Results 1 to 4 of 4
  1. #1
    Join Date
    May 2007
    Posts
    2

    Question Unanswered: How can I set the data source location through coding?

    Hi all

    I am using VB 6.0, MS Access as backend and Crystal Reports 10 for reports.
    I connect data source to Crystal Reports 10 using ODBC dsn. It works correctly in my PC. When it is distributed to another PC, where the db path is different from my PC; reports is not working.

    How can I set the data source location through coding?

    I am using the following code, but it shows the error "script out of range".

    Dim CrxApp As New CRAXDRT.Application
    Public crxRpt As CRAXDRT.Report
    Dim crxDatabaseTable As CRAXDRT.DatabaseTable

    Private Sub Form_Load()
    Dim DBTable As CRAXDRT.DatabaseTable
    If MDIForm1.strReportName = "Address Label" Then
    Set crxRpt = CrxApp.OpenReport(App.Path & "\Reports\studentmaillist.rpt")
    For Each crxDatabaseTable In crxRpt.Database.Tables
    crxDatabaseTable.ConnectionProperties("DSN") = sName
    Next crxDatabaseTable
    strClass = frmClassSelect.cboClass.Text
    crxRpt.Database.Tables(1).Location = "tblStudentInfo"
    crxRpt.Database.Tables(2).Location = "tblSchoolInfo"
    crxRpt.RecordSelectionFormula = "{tblStudentInfo.ClassName} like '" & (strClass) & "'"
    CRViewer1.ReportSource = crxRpt
    End If

    CRViewer1.EnableExportButton = True
    CRViewer1.EnableNavigationControls = True
    CRViewer1.EnableAnimationCtrl = True
    CRViewer1.EnablePrintButton = True
    CRViewer1.Zoom 100
    CRViewer1.ViewReport
    End Sub

    Thanks and Regards,
    Priyavenkat

  2. #2
    Join Date
    Feb 2007
    Posts
    348
    I'm not very good at this part of crystal but this looks like it to me:
    Set crxRpt = CrxApp.OpenReport(App.Path & "\Reports\studentmaillist.rpt")

  3. #3
    Join Date
    Jun 2007
    Posts
    2
    If the DSN name is same on another system then it will work.
    If you have different database in other system then try usuing connect method to address it. However in this case the DSN must be stored with same folder path.

  4. #4
    Join Date
    May 2007
    Posts
    2

    Thumbs up I got solution

    Hi,
    Thanks for your reply.

    I got the solution.

    The following code solve my purpose.
    <code>
    Dim CrxApp As New craxdrt.Application
    public crxRpt As craxdrt.Report
    Dim crxDatabaseTable1 As craxdrt.DatabaseTable

    Set crxRpt = CrxApp.OpenReport(App.Path & "\Reports\studentlist.rpt")
    strClass = frmClassSelect.cboClass.Text
    For Each crxDatabaseTable1 In crxRpt.Database.Tables
    crxDatabaseTable1.ConnectionProperties("DSN") = sName
    Next crxDatabaseTable1
    crxRpt.Database.Tables(1).Location = "tblStudentInfo"
    crxRpt.Database.Tables(2).Location = "tblSchoolInfo"
    crxRpt.RecordSelectionFormula = "{tblStudentInfo.ClassName} like '" & (strClass) & "'"
    crxRpt.ReportTitle = "Class - Sectionwise Student List"
    CRViewer1.ReportSource = crxRpt

    </code>

    thanks and Regards,
    Priya.

Posting Permissions

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