Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 22nd, 2006, 10:47 PM
Authorized User
Join Date: Nov 2004
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Default change Datasource of a crystal report at run time

Hi all,

        I want to call crystal reports(version 8.5 or 9.0) in my visual basic application. but i dont
want to add Crystal designers to my visual basic application. Instead i would like to create all the reports
using report expert(Using OLEDB method i will open my database and will add a table named customer and give all the
fields to report and in this way this report will show all the data in fields added to report.
it means no filter will be applied)

Then i want to store all of reports at some drive of my hard disk and using crystal viewer control i will
call reports as needed.

now my problem is that i need to change the Datasource of my reports at run time so that it would show the records that
i want to show. my code is like this

Dim ObjApp as new Craxdrt.application
Dim ObjRep as new Craxdrt.report

Dim Con as new ADODB.Connection
Dim Rs as new ADODB.Recordset

Private sub form_Load()

    Con.Open "Provider=Microsoft.Jet.Oledb.4.0; Datasource=C:\Data.mdb"
    Rs.open "Select * from Customer Where CustName = 'Jhon'",con,AdopenStatic,AdlockOPtimistic

    set objrep = objapp.open("C:\customer.rpt")

    objrep.Database.SetDatasource Rs

    CrViewver1.reportsource = objrep

End sub

Now this code is working fine but it is showing all the data within fields but according to requirement
of mine it should show only data for customer having name "Jhon". but it is showing data for all the customers
in spite of the fact that i have set the datasource to a recordset that only contains records for customer
named Jhon. but it is not working

if someone has any idea about this situation, kindly help. or suppose if you have any alternative method
kindly guide me to fullfil the requirements

sorry if there is any mistake in my code bcoz i have written this code in notepad...not i visual basic editor

Old February 17th, 2007, 06:05 AM
Registered User
Join Date: Feb 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

Instead of using set datasource you should use

objrep.RecordSelectionFormula = "{Customer.CustName} = 'Jhon'"

this will solve your problem.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Enable crystal report datasource dialogbox owen_xgy .NET Framework 2.0 2 November 21st, 2008 07:44 AM
Change datasource of crystal report at runtime check123 Pro VB 6 1 March 21st, 2008 05:45 AM
How to generate a crystal report at run time fozia_izhar .NET Framework 1.x 0 February 20th, 2007 02:34 AM
Change Printer at run time for crystal rpt, VB6.0 fiiyo ASP.NET 1.0 and 1.1 Basics 0 September 19th, 2006 06:58 AM
Change group at run time in Crystal Report 9.0 by priyank Beginning VB 6 0 January 6th, 2006 06:11 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.