Results 1 to 12 of 12

Thread: [RESOLVED] Changing Datasource in VB6 using Crystal

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Location
    Marion, IN
    Posts
    14

    Resolved [RESOLVED] Changing Datasource in VB6 using Crystal

    I am trying to change the datasource for a crystal report in VB6 and it still looks at the report datasource when it was built. I am trying to use the code

    report.database.setdatasource e:\ware.mdb,3,1

    It is still trying to find it in the old location when the report was built.

    e:\ware\ware.mdb

    I am trying to change this on the fly so that I can place the database anywhere and just change the location in an INI file which the VB program reads on startup.

    Thanks.
    Last edited by randy1227; Oct 27th, 2005 at 11:07 AM.
    Randy1227

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Changing Datasource in VB6 using Crystal

    I dont think you can pass the mdb location for the datasource. You need to pass an ADO recordset as the Datasource like you posted. Check my example in my signature - VB6/CR Ex.

    Moved from Classic VB forum.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Changing Datasource in VB6 using Crystal

    Welcome to the forums.

    You need to pass the a recordset as Rob indicates.

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2005
    Location
    Marion, IN
    Posts
    14

    Re: Changing Datasource in VB6 using Crystal

    Quote Originally Posted by RobDog888
    I dont think you can pass the mdb location for the datasource. You need to pass an ADO recordset as the Datasource like you posted. Check my example in my signature - VB6/CR Ex.

    Moved from Classic VB forum.
    Your code did not show up. could you please post it.
    Randy1227

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Changing Datasource in VB6 using Crystal

    Maybe you have a popup blocker? Anyways here is a copy of the links code.
    VB Code:
    1. Option Explicit
    2. 'Add reference to Crystal Reports x.x ActiveX Designer RunTime Library
    3. 'Add reference to Crystal Reports Viewer Control
    4. 'Add reference to Microsoft ActiveX Data Objects 2.x Library
    5. 'oCnn = current open ADO connection object
    6. Private Sub Command1_Click()
    7.  
    8.     Dim oApp As CRAXDRT.Application
    9.     Dim oReport As CRAXDRT.Report
    10.     Dim oRs As ADODB.Recordset
    11.     Dim sSQL As String
    12.  
    13.     sSQL = "SELECT * FROM Table1"
    14.     Set oRs = New ADODB.Recordset
    15.     Set oRs = oCnn.Execute(sSQL)
    16.     Set oApp = New CRAXDRT.Application
    17.     Set oReport = oApp.OpenReport(App.Path & "\MyReport.rpt", 1)
    18.     oReport.Database.SetDataSource oRs, 3, 1 '<--Pass an ADO Recordset here
    19.     crvMyCRViewer.ReportSource = oReport
    20.     crvMyCRViewer.ViewReport
    21.  
    22. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    New Member
    Join Date
    Oct 2005
    Posts
    15

    Re: [RESOLVED] Changing Datasource in VB6 using Crystal

    Ok, What if we want to change the whole SQL database ? Preferable using ODBC connection?

    e.g If design time used Connection "ODBC1" and on run time it should use "ODBC2"? I am using CR XI.

    Thanks.

  7. #7
    Member
    Join Date
    Sep 2005
    Posts
    58

    Re: Changing Datasource in VB6 using Crystal

    Quote Originally Posted by RobDog888
    Maybe you have a popup blocker? Anyways here is a copy of the links code.
    VB Code:
    1. Option Explicit
    2. 'Add reference to Crystal Reports x.x ActiveX Designer RunTime Library
    3. 'Add reference to Crystal Reports Viewer Control
    4. 'Add reference to Microsoft ActiveX Data Objects 2.x Library
    How do I do this??!?!?!? I can't figure it out, PLEASE HELP!

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] Changing Datasource in VB6 using Crystal

    For line 1 and 3...
    Project > References... > check/select each reference > click Ok.

    For line 2...
    Project > Components > Controls tab > check/select CR Viewer Control > click OK.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: [RESOLVED] Changing Datasource in VB6 using Crystal

    I change the database location of Crystal reguarly using VB and Aceess databases. It wis different between verison 8 of Crystal and versions newer then that. If you would like an example let me know and I' post them.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  10. #10
    Member
    Join Date
    Sep 2005
    Posts
    58

    Re: [RESOLVED] Changing Datasource in VB6 using Crystal

    Quote Originally Posted by GaryMazzone
    I change the database location of Crystal reguarly using VB and Aceess databases. It wis different between verison 8 of Crystal and versions newer then that. If you would like an example let me know and I' post them.
    If you could post examples that would help out a ton!

  11. #11
    Addicted Member jeanette_db's Avatar
    Join Date
    Oct 2005
    Location
    DC, Phil
    Posts
    215

    Re: [RESOLVED] Changing Datasource in VB6 using Crystal

    hi... how about changing datasources using data report? does anybody know?? pls help??

  12. #12
    Member
    Join Date
    Sep 2005
    Posts
    58

    Exclamation Re: [RESOLVED] Changing Datasource in VB6 using Crystal

    Quote Originally Posted by GaryMazzone
    I change the database location of Crystal reguarly using VB and Aceess databases. It wis different between verison 8 of Crystal and versions newer then that. If you would like an example let me know and I' post them.

    I have been working on this for over two months now and can't figure it out if you could post examples that would be great. I have tried EVERYTHING!!

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