Solved

Crystol Reports Selection Formula

Posted on 1997-10-12
4
291 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
[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
  • 2
4 Comments
 
LVL 1

Expert Comment

by:haas090897
ID: 1437321
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
ID: 1437322
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
ID: 1437323
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
ID: 1437324
Yes, i've got that to work now, thank you.
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

749 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