Solved

Crystal Report Database Query

Posted on 2003-12-10
15
586 Views
Last Modified: 2007-12-19
I would like to be able to change the query of a Crystal Report on the fly.

I have the query built into a command in the designer at the moment.

Can any one help me?
0
Comment
Question by:Terry Rogers
15 Comments
 
LVL 30

Expert Comment

by:nmcdermaid
ID: 9913049
I'm not sure what you mean by 'built into a command'

However, in Visual Basic, add references to the Crystal libraries (Project/References), that will get you started. It allows you to change various properties of a crystal report and then run it.
0
 
LVL 1

Author Comment

by:Terry Rogers
ID: 9913180
ok, Im using a Crystal Report designer within my VB app.

When I click the designer it shows me the design of the report.

On the left it says "Database Fields" and under this is "Command" with the Fields from the "Command" SQL Statement coming off of it.

If I go into the database expert I can see on the right the server address and under that another item called command which I created with my SQL query in. To edit the sql query in that command I right click on it and select edit command.

I need to be able to edit this command from within my VB code and not the designer.

Hope ive made things a little more clear.
0
 
LVL 30

Expert Comment

by:nmcdermaid
ID: 9913497
Ah, OK, I am using the full version of Crystal rather than the VB version at the moment so I got a bit confused, sorry.



This will work in theory but I avoid the data environment so I haven't used it much.

DataEnvironmantName.Commands("CommandName").CommandText = "New SQL Query"

Make sure the query returns the same number of fields and ensure they have the same names.
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 30

Expert Comment

by:nmcdermaid
ID: 9913557
Oh yeah, now that I have had a hack, the command has to be a SQL statement rather than a table, otherwise that will just change the table name rather than the whole SQL statement.
0
 
LVL 1

Author Comment

by:Terry Rogers
ID: 9914453
This is good except im not using a data environment, so how can I change the command in the report?

My designer is called CrystalReport,

And I dont have a CrystalReport.Commands options, I have a CrystalReport.Database but I still cant find the command thing your referring to.
0
 
LVL 1

Author Comment

by:Terry Rogers
ID: 9914522
I have found that CrystalReport.SQLQueryString is holding my query but when I try to change it it doesn't change.
0
 
LVL 1

Author Comment

by:Terry Rogers
ID: 9914543
Also im using Crystal Reports 9 if thats of any help.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 9917663
What you are trying to do may require the Crystal Reports 9 Designer Design and Run Time library (CRAXDDRT.dll).  This may also incur a requirement for you to purchase runtime licenses for all users ($199 per license).  

In general you cannot change the select part of the query.  It may be possible with the CRAXDDRT library.

mlmcc
0
 
LVL 1

Author Comment

by:Terry Rogers
ID: 9918820
This has come from CrystalDevHelp.chm.

Property: SQLQueryString
Description: String. Gets or sets SQL query string.
Read/Write: Read/Write
Restriction in event handler: Can be written only when formatting idle.

It seems this is what I need to change, and it is a read/write property. But how can I make "formatting idle"?
0
 
LVL 30

Expert Comment

by:nmcdermaid
ID: 9918910
Formatting Idle sounds lke it means you can only change it when the report is not running, which is what you are doing anyway.

Sorry I will have to bow out as I only have version 7, and I can't find the crystal reports designer option in VB.

There is one other option and that is to base the report on a view (A SQL Server view or a MS Access query) then change the view in the database. It's a bit hairy though and really you shouldn't have to if Crystal help says you can change the source query.

Good Luck!

0
 
LVL 1

Expert Comment

by:vbnewby
ID: 9919443
This may not be the correct answer to your question, but it is the way I have got around it.

I first created a report table in the database, had my SQL statment populate the report table, then had crystal report look at that table



0
 
LVL 1

Author Comment

by:Terry Rogers
ID: 9919988
vbnewby, this seems like a solution but it seems a bit long winded.

Anyone, anyone at all who can come up with a good solution to this problem would be great.

getting more and more desperate by the minute. :-\
0
 
LVL 30

Expert Comment

by:nmcdermaid
ID: 9920215
Like I said there is the view option but it is also a little bit long winded.
0
 

Accepted Solution

by:
SerCouWisMOD earned 0 total points
ID: 9966975
A request has been made to close this question and refund the points;
http://www.experts-exchange.com/Community_Support/Q_20829593.html
If there are no objections within the next 72 hours, the request will be granted.

EXPERTS: Please leave your thoughts on the request here.

SerCouWisMOD
Community Support Moderator
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

770 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