Solved

Crystal Report v7  SelectionFormula

Posted on 2003-10-27
4
984 Views
Last Modified: 2008-01-16
Hi all expert,

I have a VB6 program using Crystal Report Control trying to print a Crystal Report (v7).
The codes for printing worked fine.
     crysReport.Connect = PRptConn
     crysReport.ReportFileName = PReportPath & vRptName & ".rpt"
     crysReport.Action = crptToPrinter

But now I want to add codes to do something like we do directly in Crystak Report (v7):  Report  > Edit Selection Formula > Record...
I have a problem trying to pass a text value to  .SelectionFormula. I even tried to replace the single quotes with Chr(34) or Chr(39), but neither of then worked.
     crysReport.Connect = PRptConn
     crysReport.ReportFileName = PReportPath & vRptName & ".rpt"
     crysReport.SelectionFormula = "{TableName.FieldName}= '" & vValue &"'"
     crysReport.Action = crptToPrinter

I got an error message below:
                Run-time error '20515'
      Error in formula <Record_selection>.
      .
      .
      The remaining text does not appear to be part of the formula.

Please advise.

Thanks in advance and best regards.
0
Comment
Question by:mingichu
  • 2
4 Comments
 
LVL 100

Accepted Solution

by:
mlmcc earned 200 total points
Comment Utility
I think you may need a space before the =
Try this

crysReport.SelectionFormula = "{TableName.FieldName} = '" & vValue.Text &"'"

I usually use

crysReport.ReplaceSelectionFormula  "{TableName.FieldName} = '" & vValue.Text &"'"

mlmcc
0
 

Expert Comment

by:JMCrenshaw
Comment Utility
I can remeber having a similar problem previously, much like some of the API calls strings must be Null Terminated. I found that by appending your string with a vbnull that worked for me and passing the Selection formula via a string rathern than directly into the object.

Example

crysFormulaString = "{TableName.FieldName}= '" & vValue & vbnull
crysReport.SelectionFormula = crysFormulaString

or  I have also used the Cstr() function

crysFormulaString = Cstr("{TableName.FieldName}= '" & vValue)
crysReport.SelectionFormula = crysFormulaString

Hope this helps !
0
 

Author Comment

by:mingichu
Comment Utility
Thank you both very much for your quick response!!!!
I still got the same error when I tried the both solution using .SelectionFormula.

But it works using .ReplaceSelectionFormula.

Thanks a zillion for your help!!
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
Glad I could help.

mlmcc
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now