Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 22nd, 2006, 10:47 PM
Authorized User
 
Join Date: Nov 2004
Location: Lahore, , Pakistan.
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
    Crviewver1.ViewReport

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

                    Tayyab
__________________
Tiyyob
Reply With Quote
  #2 (permalink)  
Old February 17th, 2007, 06:05 AM
Registered User
 
Join Date: Feb 2007
Location: mumbai, maharashtra, India.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Instead of using set datasource you should use

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

this will solve your problem.

Sachin
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 02:45 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.