Embedded Quotes in Visual Basic Calls to the Crystal Report Engine

When you pass a concatenated string from Visual Basic to the Crystal Report Engine (for example, for a record selection formula), it is important that the resulting string has the exact syntax that the Crystal Report Engine expects. You should pay special attention to embedded quotes in concatenated strings because they are often the source of syntax errors.

Several examples follow. The first example shows code with a common embedded quote syntax error and the last two examples show code using the correct syntax.

Incorrect syntax

VBNameVariable$ = "John"
Recselct$ = "{file.LASTNAME} = " + VBNameVariable$

This code results in the string:

{file.LASTNAME} = John

Since John is a literal string, the Formula Checker expects to see it enclosed in quotes. Without the quotes, the syntax is incorrect.

Correct syntax

VBNameVariable$ = "John"
Recselct$ = "{file.LASTNAME} = " +
(chr$(39) + VBNameVariable + chr$(39)

This code results in the string:

{file.LASTNAME} = 'John'

This is the correct syntax for use in a Crystal Reports record selection formula. This is the syntax you would use if you were entering a selection formula directly into Crystal Reports.

VBNameVariable$ = "John"
Recselct$ = "{file.Lastname} = "
(+ "'" + VBNameVariable + "'"

This code also results in the string:

{file.LASTNAME} = 'John'

Again, the correct syntax.



Seagate Software IMG Holdings, Inc.
http://www.seagatesoftware.com
Support services:
http://support.seagatesoftware.com