?
Solved

Using CR 4.6.1.0 with VB 6

Posted on 2003-03-23
13
Medium Priority
?
402 Views
Last Modified: 2012-06-27
Hello,
I am developing an application in VB with Access backend.
I need to generate reports based on the outputs of the datacontrol in the form. The .DataSource for the datacontrol changes every time since it does varied search on the database tables.
I have designed a format of the report in Crystal Report 4.6.1 with all the required fields and named it "searchreport1.rpt".
And I have added the Crystal Reports control to the Result-display-form
I also have provided a button on the form which can be used to get the reports printed.
The .RptFileName has been set to the .rpt file as well.
The .ReportSource has been set to 3-crptDataControl.
How can I set the Datasource property of the CR Control to the datacontrol(machinedatasearch) on clicking the "Print Report" button on the form?.I need to do this since there are 2 datacontrols in the form.
I have already tried
rpt1.DataSource = machinedatasearch
When I give the rpt1.Action = 1 , I do get the  correct results printed.But they are not in the required format.
When the .ReportSource property of the CR control is set to the datacontrol,I seem to get the correct results but in the wrong format,ie, all the fields in the table are printed and there is not formatting whatsoever.
When the .ReportSource is set to the Report,I get the wrong results,ie all the records in the table gets printed without any filtering,but I do get the correct format.I had set some font formatting and bordering in the .rpt file.All these things get printed nice and fine.
Please give the details as I don't have much idea about how to use the CR to generate reports dynamically.
0
Comment
Question by:vinaylak
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
13 Comments
 
LVL 101

Expert Comment

by:mlmcc
ID: 8189942
Since you have now put all the pieces in one place, I think I see the problem.

Are you Saving data with the report?

Open the report in CR
Click FILE
Ensure SAVE DATA WITH REPORT is not checked.

Another way (later versiions of CR)
Before the Action line

rpt1.DisacardSavedData

mlmcc
0
 

Author Comment

by:vinaylak
ID: 8193303
To Mlmcc,
That doesn't work either since the option is already unchecked.I have also tried the .DiscardSavedData property of the CR control.That doesn't work either.
I am beginning to get depressed!
This is all the code in both the buttons:
This is the first button.It is supposed to print all the fields in the table in a required format(datareport.rpt)
*********************************************************
Private Sub prntresultswhole_Click()
If machinesuccess1 = 1 Then
    machinedatasearch.RecordSource = "SELECT * FROM machinedata WHERE modelname='" & machinedet & "'"
    'rptwhole.SQLQuery =  "SELECT * FROM machinedata WHERE modelname='" & machinedet & "'"
    machinedatasearch.Refresh
    machinesuccess1 = 0
End If
rptwhole.Action = 1
rptwhole.DiscardSavedData
End Sub
**********************************************************
And this is the code in the second button,which is supposed to print an abridged report for the same query.
Obviously ,it shouls contain only a couple of fields in the table.
**********************************************************
Private Sub prntresultssub_Click()
If machinesuccess1 = 1 Then
    'rptsub.SQLQuery =  "SELECT * FROM machinedata WHERE modelname='" & machinedet & "'"
    machinedatasearch.RecordSource =  "SELECT * FROM machinedata WHERE modelname='" & machinedet & "'"
    machinedatasearch.Refresh
    machinesuccess1 = 0
End If
rptsub.Action = 1
rptsub.DiscardSavedData
End Sub
**********************************************************
Properties for rptwhole and rptsub are:
Properties        rptwhole                      rptsub
----------      ----------------       -------------------
Name            rptwhole                      rptsub
DataSource      machinedatasearch       machinedatasearch
Destination     crptToPrinter               crptToPrinter
DiscardSaved..  True                            True
Reportfilename  pth\datareportwhl.rpt  pth\datareport1.rpt
ReportSource    crptReport             crptReport
**********************************************************
Please help me out somehow.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 8195923
WHat is the SQL the report is built against?

mlmcc
0
Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

 

Author Comment

by:vinaylak
ID: 8200779
I have built the report with all the fields in the 2 table in the database.
Besides it would be impossible to suggest a specific query for the report since the reports are to be generated based on search criteria and search results.
The Code field in both the tables have been set as the primary key and the index field.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 8203166
The report should be built on the following query

Select Table1.*, Table2.* FROM
Table1 JOIN Table2 ON
Table1.Code = Table2.Code

In the code you can then

rpt.ReplaceSelectionFormula = FilterCriteria

FilterCriteria is a where clause to restrict the data from the database.

mlmcc
0
 

Author Comment

by:vinaylak
ID: 8210448
To mlmcc,
Thanks a lot for coming to my rescue again and again and again.But by sad fate,I am still unable to make use of your help.
The reason being that,I don't know how I can build a report based on an SQL Query.Can you please explain?I have always used the Report Designer to get the required fields in the necessary format.Not that I have done it many times either.
And can you please give an example for the ".ReplaceSelectionFormula" properties usage?
Please be patient as I am just learning the process myself.Thanks a lot again.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 8214214
Can you build a query in the database?  That is the best place because CR SQL is limited and prone to errors.

What tables are you trying to use?  

mlmcc
0
 

Author Comment

by:vinaylak
ID: 8253323
I have 2 tables,one for the customers data and the other for machine data for each purchase or enquiry by a customer.
I need to search data in these tables and get them printed with the CR. So the criteria will be different in each search. Since this is the case,will it be possible for me to build a query inthe database,each time the criteria changes?. Even if I do this, how can I get it printed with CR?
Please explain how you can build a report on an SQL QUERY.

0
 
LVL 101

Accepted Solution

by:
mlmcc earned 300 total points
ID: 8257426
Yes.  I always build the queries in the database and don't use a where, group by, or order by clauses unless it will remain that way for every report.

From your application you can use

crRpt.ReplaceSelectionFormula = "The filter clause"
It is simply the where clause without the word where.  You can use variables and controls from your form.

crRpt.ReplaceSelectionFormula = "{View.Name} = 'Mike'"
crRpt.ReplaceSelectionFormula = "{View.Name} = '" & txtName.text & "'"

mlmcc
0
 

Author Comment

by:vinaylak
ID: 8321335
At last I have managed to get hold of a newer version of CR.It is CR7.But I have no idea how I can use it.It just gives a CRViewer in the components list.How can I configure it to display or print a previously designed report(done using report designer)?
I have added references to all the CR7 elements in the reference list.
0
 

Author Comment

by:vinaylak
ID: 8321339
At last I have managed to get hold of a newer version of CR.It is CR7.But I have no idea how I can use it.It just gives a CRViewer in the components list.How can I configure it to display or print a previously designed report(done using report designer)?
I have added references to all the CR7 elements in the reference list.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 8322160
The same code you used with 4.6 should work with the OCX control.

What references did you add?

mlmcc
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 11229445
Glad I could help

mlmcc
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question