Google Answers Logo
View Question
 
Q: Visual Basic and Crystal Reports ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: Visual Basic and Crystal Reports
Category: Computers > Programming
Asked by: bigjohnbn-ga
List Price: $5.00
Posted: 10 Nov 2002 07:17 PST
Expires: 10 Dec 2002 07:17 PST
Question ID: 104564
How can a I add a title to my crystal report at run time?
So far, I am able to display and print the report, as well as change
the selection criteria at run time.

Request for Question Clarification by hammer-ga on 10 Nov 2002 07:29 PST
What version of VB? What version of Crystal Reports?
Answer  
Subject: Re: Visual Basic and Crystal Reports
Answered By: hammer-ga on 10 Nov 2002 09:05 PST
Rated:5 out of 5 stars
 
In Crystal Reports, you insert a Formula into your report named
@Title.

In VB, you assign it as follows:
Rpt1.Formulas(0) = "Title= " & "The title of your report"


You can find many examples of this by using a Google Groups search
with the following search terms:
formula "Crystal Reports" VB title

Here is a link to the Crystal Reports Knowledge Base
http://support.crystaldecisions.com/library/kbase.asp

Good luck with your reports!

- Hammer

Request for Answer Clarification by bigjohnbn-ga on 11 Nov 2002 04:15 PST
I thought I knew what to do, but when I actually try it, I have
problems.

I have used the Add Crystal Reports 8.5 option from the Project menu
to create the boilerplate code.  I have modified the second form the
read as follows:

rivate Sub Form_Load()
Screen.MousePointer = vbHourglass
CRViewer1.ReportSource = Report
Report.RecordSelectionFormula =
"{Receipts.Date}>datetime(2002,10,15,00,00,00)"
'Report.FormulaFields(2).Text = "test"
CRViewer1.ViewReport
Screen.MousePointer = vbDefault

As long as I leave the comment indicator in the Report.FormulaFields
line, the program works OK with the title I created initially.
I can change the selected records with the Record Selection line, so
I'm pretty sure I have the general paramaters set OK.
I can take the comment indicator away on the next line and remove the
title from the report as follows:

Report.FormulaFields(2).Text = ""

However, if I try:

Report.FormulaFields(2).Text = "test"

I get a Crystal Report Viewer error, indicating that "The remaining
text does not appear to be part of the formula"

I have tried several things that don't work.  I'm sure this is
something very minor, but I don't know what to do next.

Clarification of Answer by hammer-ga on 11 Nov 2002 06:58 PST
The string that you pass sets the formula itself, not just the Title
text.

Your code:
Report.FormulaFields(2).Text = "test"
sets the formula itself to "test", which does not evaluate.

I'm also not sure about the FormulaFields part. All the examples I saw
simply said Formulas.

If your formula is named @Title, try something like:
Report.Formulas(0).Text = "Title = test" or

Request for Answer Clarification by bigjohnbn-ga on 11 Nov 2002 08:03 PST
I had tried something similiar to that.  My code now reads:

Private Sub Form_Load()
Screen.MousePointer = vbHourglass
CRViewer1.ReportSource = Report
Report.RecordSelectionFormula =
"{Receipts.Date}>datetime(2002,10,15,00,00,00)"
Report.Formulas(0).Text = "Title = test"

CRViewer1.ViewReport
Screen.MousePointer = vbDefault


I receive an error indicating "Method or data member not found"  with
.Formulas highlighted.

If I change it to 
Report.FormulaFields(0).Text = "Title = test" I get an error
indicating Subscript out of range.

Report.FormulaFields(1).Text = "Title = test" gives me an error of
"Remaining text does not seem to be part of the formula.

The latest error is a Crystal Viewer error, the others are labelled
"Microsoft Visual Basic" errors.

When I try to type Report.Formulas(0), the program suggests
Report.FormulaFields instead.  I have tried all of these combinations
both ways.

I am running VB 6.0   and Crystal Reports 8.5

Any help you could give would be greatly appreciated.

Request for Answer Clarification by bigjohnbn-ga on 11 Nov 2002 08:33 PST
I found a way to get around my problem.  I have created a new table
within the database that I am using.  This table contains just the
title that I want to use.  I update the table using Visual Basic and
then use that field in the heading of the Crystal Report.  It's seems
like a lot of work, but at least it gives the result I want.

Clarification of Answer by hammer-ga on 11 Nov 2002 10:11 PST
Unfortunately, I don't have a testbed with the same software versions
as you have. I'm glad you found a workaround. If you go to the
Knowledge Base link I sent you and search on "Title", you will find
articles on how to do this using Formula and FormulaFields. Crystal
clearly believes that this can be done from VB, but I don't have the
ability to set up the correct Project References to work it out for
you.
bigjohnbn-ga rated this answer:5 out of 5 stars and gave an additional tip of: $5.00
Thank you very much for your quick answer.  I also appreciate the
links and search suggestion.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy