Solved

Crystal Report v7  SelectionFormula

Posted on 2003-10-27
4
992 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
ID: 9628924
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
ID: 9628948
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
ID: 9629921
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
ID: 9630808
Glad I could help.

mlmcc
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…

778 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