[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 297
  • Last Modified:

Crystol Reports Selection Formula

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
ncw
Asked:
ncw
  • 2
  • 2
1 Solution
 
haas090897Commented:
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
 
ncwAuthor Commented:
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
 
haas090897Commented:
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
 
ncwAuthor Commented:
Yes, i've got that to work now, thank you.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now