Solved

Crystal Report v7  SelectionFormula

Posted on 2003-10-27
4
1,004 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
[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
  • 2
4 Comments
 
LVL 101

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 101

Expert Comment

by:mlmcc
ID: 9630808
Glad I could help.

mlmcc
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…
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…
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

631 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