Results 1 to 3 of 3

Thread: DSN Using in VB6.0 with CR10

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2008
    Posts
    17

    Exclamation DSN Using in VB6.0 with CR10

    Hi,
    Im using VB6.0, Crystal report 10 and MSaccess Database. I was using Crystal report 6 and later upgraded to CR10. In VB6 i used DSN like
    .Connect = "DSN=DBName" & ";UID=admin;PWD=;"
    Now in CR10 i have created reports without using DSN in VB. Can any help how to use DSN in VB6.0 with CR10 or is there any method so that i no need to use DSN in the above said requirements.

    The code used for CR10 is
    Set Report = Appl.OpenReport(App.Path & "\SampleReport.rpt")
    CRViewer1.ReportSource = Report
    CRViewer1.Visible = True
    CRViewer1.ViewReport

    Please guide me in using/without using DSN
    THANKS in advance.
    Last edited by kselvakumar_82; Apr 10th, 2008 at 07:06 AM.

  2. #2
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: DSN Using in VB6.0 with CR10

    Let's see Crystal Reports 10 alone
    When reporting from an MS Access 2003, You can use one from the next
    methods to define a datasource in the report

    1.- Database Expert / Create New Connection / Access/Excel (DAO) or
    2.- Database Expert / Create New Connection / Database Files or
    3.- Database Expert / Create New Connection / OLE DB (ADO)
    with a Microsoft Jet 4.0 OLE DB Provider or
    4.- Database Expert / Create New Connection / OLE DB (ADO)
    with a Microsoft OLE DB Provider for ODBC Drivers
    (using this way, you need to define an DSN that points to the file)
    5.- (more...)

    Now, Let's see VB6 and Crystal Reports 10:

    You need to reference :
    Crystal Reports ActiveX Designer Run Time Library 10.0
    Crystal ActiveX Report Viewer Library 10.0
    ( this, only if you want to preview the reports)

    You need to declare the objects & variables
    Code:
    Global CRApplication    As New CRAXDRT.Application
    Global CRReport         As New CRAXDRT.Report
    Global CRConProp        As CRAXDRT.ConnectionProperty
    Global CRTable          As CRAXDRT.DatabaseTable
    Global MInt2            As Integer
    Global MyPath		As String 'Store the relative Path to data & rpts
    And use the .ConnectionProperty to change at runtime the desired
    data source values according to the way that you defined it in
    Crystal Reports (1 of the 4 ways defined earlier)

    Samples:
    Code:
    'If you defined the datasource using DAO
    Set CRReport = CRApplication.OpenReport(MyPath & "\RptName1.rpt", 1)
        
    For MInt2 = 1 To CRReport.Database.Tables.Count
        Set CRTabla = CRReport.Database.Tables(MInt2)
        Set CRConProp = CRTabla.ConnectionProperties("Database Type")
            CRConProp.value = "Access/Excel (DAO)"
        Set CRConProp = CRTabla.ConnectionProperties("Database Name")
            CRConProp.value = MyPath & "\FileName.mdb"
        Set CRConProp = CRTabla.ConnectionProperties("Database Type")
            CRConProp.value = "Access"
        Set CRConProp = CRTabla.ConnectionProperties("Session UserID")
            CRConProp.value = ""
    Next MInt2
    
    
    'If you defined the datasource using ADO
    Set CRReport = CRApplication.OpenReport(MyPath & "\RptName2.rpt", 1)
        
    For MInt2 = 1 To CRReport.Database.Tables.Count
        Set CRTabla = CRReport.Database.Tables(MInt2)
        Set CRConProp = CRTabla.ConnectionProperties("Database Type")
            CRConProp.Value = "OLE DB (ADO)"
        Set CRConProp = CRTabla.ConnectionProperties("Provider")
            CRConProp.Value = "Microsoft.Jet.OLEDB.4.0"
        Set CRConProp = CRTabla.ConnectionProperties("Data Source")
            CRConProp.Value = MyPath & "\FileName.mdb"
        Set CRConProp = CRTabla.ConnectionProperties("User Id")
            CRConProp.Value = "Admin"
        Set CRConProp = CRTabla.ConnectionProperties("Database Type")
            CRConProp.Value = "Access"
        Set CRConProp = CRTabla.ConnectionProperties("Locale Identifier")
            CRConProp.Value = "1033"
        Set CRConProp = CRTabla.ConnectionProperties("OLE DB Services")
            CRConProp.Value = "-6"
    Next MInt2
    
    
    'If you defined the datasource using ODBC
    Set CRReport = CRApplication.OpenReport(MyPath & "\RptName3.rpt", 1)
    
    For MInt2 = 1 To CRReport.Database.Tables.Count
        Set CRTabla = CRReport.Database.Tables(MInt2)
        Set CRConProp = CRTabla.ConnectionProperties("Provider")
            CRConProp.value = "MSDASQL"
        Set CRConProp = CRTabla.ConnectionProperties("Data Source")
            CRConProp.value = DSNName
        Set CRConProp = CRTabla.ConnectionProperties("User ID")
            CRConProp.value = ""
        Set CRConProp = CRTabla.ConnectionProperties("Locale Identifier")
            CRConProp.value = "2058"
        Set CRConProp = CRTabla.ConnectionProperties("OLE DB Services")
            CRConProp.value = "-5"
     Next MInt2
    Of course, there are some other ways, but I think this are ok for a start

    JG

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2008
    Posts
    17

    Re: DSN Using in VB6.0 with CR10

    Thanks jggtz for your reply.

    Im using the third one ODBC. when i have the above code im getting error as Subscript out of range in the line
    Set CRConProp = CRTabla.ConnectionProperties("Microsoft.Jet.OLEDB.4.0")

    Can you please guide me in using the DSN for the requirement mentioned please.
    Last edited by kselvakumar_82; Apr 12th, 2008 at 01:07 AM.

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