Solved

Crystol Reports Selection Formula

Posted on 1997-10-12
4
285 Views
Last Modified: 2012-08-14
I want to set the data selection criteria in VB (ie not within Crystol Reports). The following code gives an "Error in formula" message:

Report1.SelectionFormula = "[ContactRef]='Client'"

Can you help please.
0
Comment
Question by:ncw
  • 2
  • 2
4 Comments
 
LVL 1

Expert Comment

by:haas090897
Comment Utility
The syntax for Selectionformula is {tablename.field}='value', in your case you use the wrong bracket type around the table.field clause. If you are not sure about the syntax try using Crystal report and edit the formula in the Record Selection formula Editor. You will be able to check the syntax at once by the Check button. When you are finished you just cut and paste to vb, replace the value by a dynamic value.
The code would look something like this:
Report1.SelectionFormula = "{tablename.field}='" szVariable & "'"
Hope this would help.
0
 
LVL 1

Author Comment

by:ncw
Comment Utility
I have cut and pasted your code into the program, replacing your text as follows:

Report1.SelectionFormula = "{Contacts.ContactRef}='"Client"'"

but this gives the 'Expected end of statement' message.

I've tried altering the combination of " and ' without success.

Should this code form part of a query SQL?

0
 
LVL 1

Accepted Solution

by:
haas090897 earned 100 total points
Comment Utility
The word client should not be between ", in your case the formula would look like this:
Report1.SelectionFormula="{Contacts.ContactRef}='Client'" or

dim myVariable  as string
myVariable="Client" 'This value may be altered

Report1.SelectionFormula="{Contacts.ContactRef}='" &
myvariable & "'"
or why not like this:
dim myVariable  as string
myVariable="{Contacts.ContactRef}='Client'" 'This value may be altered

Report1.SelectionFormula=myvariable
The main thing is that textvalues in formulas must be enclosed
by ' '.

Look at your code and count the ", after the second " the string is terminated, to continue the string you need to set the &
after the ", and so on. Easy string manipulation.

In the first answere even i missed the &, sorry.
Better luck this time!
0
 
LVL 1

Author Comment

by:ncw
Comment Utility
Yes, i've got that to work now, thank you.
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

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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

772 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

11 Experts available now in Live!

Get 1:1 Help Now