User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 456,497 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,737 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums
Views: 2316 | Replies: 12
Reply
Join Date: Sep 2007
Posts: 50
Reputation: kehar is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
kehar kehar is offline Offline
Junior Poster in Training

Help connecting and passing query in VB6 and CR

  #1  
Sep 22nd, 2007
Sir, I have prepared programme using VB6 and Access2003. The programme is working very fine so far as adding,deleting,modifying the record through VB is concerned. I have installed Crystal Report 8.5 and have prepared a report and save as (bill.rpt) but I dont know how to connect the report with VB. The path of report is C:\ks\bill.rpt and path of database in Access is C:\ks\exp.mdb
I shall be grateful if you kindly help me
1. to connect the report with VB and
2. to pass a query in which if I enter America in Text1.text in VB and Click the command button VIEW the report should generate only the name and age of all the person who live in America within the field (address).
The Data base fieldname are Name, age and address

I am very new to CR so pl write all the code to write within the click event procedure of command button VIEW so that I may not add anything else.

thanking you in anticipation

Keshar
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2007
Location: India
Posts: 501
Reputation: choudhuryshouvi is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 48
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Solution Re: connecting and passing query in VB6 and CR

  #2  
Sep 24th, 2007
you have to create an ODBC connection with the access database to connect your program to the crystal report. then create an query and make the report based on that query. after that you will call the query in your program and the rest will be handled by ur apps.

first of all u have to create an query in ur access db. then...

if u r not familiar with how to create an access odbc connection plz follow the steps:-

1.goto control panel->administrative tools->database(odbc connection)
2.in user dsn tab select add
3.select microsoft access driver .mdb from list and click finish
4.enter ur dsn name(this can be anything)
5.click select and locate ur access db
6.click ok
7.then ok again to create the dsn

after creating it goto crystal report and select the dsn under the odbc section from the connection tree while u select to create a new blank report.

use the query what u created in ur db to fetch the fields from it into the report. create the report based on that query.

after this use the following code to create the query dynamically to run it from ur vb6 apps:-

Dim db As Database
Dim qdf As QueryDef
Set db = CurrentDb()
Set qdf = db.CreateQueryDef("MyQuery", "SELECT * FROM MyTable")
Set db = Nothing

then use a crystal report control and pass ur dbname,query and report name as parameters. ur program now should call the report.

hope it'll work.
regards
Shouvik
Reply With Quote  
Join Date: Sep 2007
Posts: 50
Reputation: kehar is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
kehar kehar is offline Offline
Junior Poster in Training

Re: connecting and passing query in VB6 and CR

  #3  
Sep 25th, 2007
Sir,
thanks for your reply
I am very new to CR so I could not understand second part of your reply starting from
create query ....
I know how to prepare DSN in database
for your information I am giving you some hints
my dsn is exp
my database file path is C:\home\exp.mdb
database field are billno, chequeno, chequedt,month
In vb form I've placed crystal report control , one text box (text1.text) and one command window.

my problem is - when I run the VB and type "January" in text1.text and click the command botton the report should contain all billno,chequeno,chequedt pertaining to the month of January
similarly if I write February the report should contain all billno,chequeno,chequedt pertaining to the month of February.

I know the query statement to retrieve data from database to grid in VB that is written as :-
Select * from exp where month=' " & text1.text & " '
but I dont know the statement to retrieve the data from the Report

So I shall be grateful if you write the step by step procedure. I am dummy so far as CR is concerned.
Reply With Quote  
Join Date: Sep 2007
Posts: 50
Reputation: kehar is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
kehar kehar is offline Offline
Junior Poster in Training

Re: connecting and passing query in VB6 and CR

  #4  
Sep 25th, 2007
Sir,
thanks for your reply
I am very new to CR so I could not understand second part of your reply starting from
create query ....
I know how to prepare DSN in database
for your information I am giving you some hints
my dsn is exp
my database file path is C:\home\exp.mdb
database field are billno, chequeno, chequedt,month
In vb form I've placed crystal report control , one text box (text1.text) and one command window.

my problem is - when I run the VB and type "January" in text1.text and click the command botton the report should contain all billno,chequeno,chequedt pertaining to the month of January
similarly if I write February the report should contain all billno,chequeno,chequedt pertaining to the month of February.

I know the query statement to retrieve data from database to grid in VB that is written as :-
Select * from exp where month=' " & text1.text & " '
but I dont know the statement to retrieve the data from the Report

So I shall be grateful if you write the step by step procedure. I am dummy so far as CR is concerned.
Reply With Quote  
Join Date: May 2007
Location: India
Posts: 501
Reputation: choudhuryshouvi is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 48
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Help Re: connecting and passing query in VB6 and CR

  #5  
Sep 25th, 2007
use the code in the zip file.
hope it'll help you.
but before run the code create the dsn with name "exp" and mention the database path of the database "exp". the path should be where u installed the db from the zip file.

regards
Shouvik
Attached Files
File Type: zip Access.zip (12.4 KB, 28 views)
Reply With Quote  
Join Date: Sep 2007
Posts: 50
Reputation: kehar is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
kehar kehar is offline Offline
Junior Poster in Training

Re: connecting and passing query in VB6 and CR

  #6  
Sep 26th, 2007
The Zip file is not opening even after log in with daniweb as such I once again request your goodself to send the zip file at my email id - kehar2005@gmail.com as attach file ple.

Thanks

K.S. Chhetri
Reply With Quote  
Join Date: May 2007
Location: India
Posts: 501
Reputation: choudhuryshouvi is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 48
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: connecting and passing query in VB6 and CR

  #7  
Sep 26th, 2007
are u using internet explorer?
might IE is not supporting this download

download mozilla firefox browser from http://www.mozilla.com and try the download from that browser.

i'm telling you because i've tried downloading the file using firefox and it was successfully downloaded.
Reply With Quote  
Join Date: May 2007
Location: India
Posts: 501
Reputation: choudhuryshouvi is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 48
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: connecting and passing query in VB6 and CR

  #8  
Sep 26th, 2007
ok, for ur convenience i've sent it to ur mail.
check it and for further references if u wish can mail me at choudhuryshouvik@gmail.com

regards
Shouvik
Reply With Quote  
Join Date: Sep 2007
Posts: 50
Reputation: kehar is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
kehar kehar is offline Offline
Junior Poster in Training

Re: connecting and passing query in VB6 and CR

  #9  
Sep 26th, 2007
yes, download over and extracted the file and I have to try with my programme. I will see it tell you later.
thanks
k.s
Reply With Quote  
Join Date: Sep 2007
Posts: 50
Reputation: kehar is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
kehar kehar is offline Offline
Junior Poster in Training

Re: connecting and passing query in VB6 and CR

  #10  
Sep 26th, 2007
Sir,
When I run the programme prepared by you the following error is shown

Run time error 20599
Cannot open SQL Server

So what is this error how is this rectified.

secondly when I tried to open your report only and tried to see the preview it ask for number of things how is this prepared and why ?

K.s.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Visual Basic 4 / 5 / 6 Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum

All times are GMT -4. The time now is 3:28 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC