Solved

Crystol Reports Selection Formula

Posted on 1997-10-12
4
287 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
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb6 programatically bring window to front 8 72
VB 6.0 printer how to align 6 62
Protecting vb6 & .Net code Obfuscation 18 126
Set email body to html using vbscript 6 42
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 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…

831 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