VB Script Help Follow

0
Avatar
David Shaffer

Want to suppress print if a database field contains the same information as the previous field. Printing labels for a library and if the call number field contains the author we want to not print the next field which is the author. If not then we want to print the author field. Is this possible?

4 comments

0
Avatar
Pete Thane
Comment actions Permalink

For your VB script field make it an Event Controlled Script and apply code similar to the below using the OnNewRecord option:

 

My sample label is linked to a simple 3 filed text database and compares fields f2 and f3 and if there is a match prints "" (ie nothing) otherwise it prints field f3

I hope this helos

0
Avatar
Pete Thane
Comment actions Permalink

This shows the code more clearly

Value = Field("testduplicate.testduplicate.f2")

Value1 = Field("testduplicate.testduplicate.f3")

If Value = Value1 then

Value = ""

else Value = Value1

end if

 

To link to the database fields type in the Value = then double click on the field name in the column on the right

0
Avatar
David Shaffer
Comment actions Permalink

Tried that but did not work. The problem I see is that my database field called "Call No" contains the "Author" information but also contains other data. So for example the Call No is 92 GAR and the Author field contains GAR. When this happens we do not want to print the Author field, "GAR" in this case since it will be printed in the line above it as part of the Call No.

0
Avatar
Pete Thane
Comment actions Permalink

You didn't mention that the field to be searched contained other information too and so the simple comparison will not work. 

I believe you will need to use the InStr command 

I would suggest adding a VB field off to the side of the label and give the field a Data Source Name and set this to perform the comparison. The result will be either 0 if it is not found or a higher number if it is (actually the position of where the searched for item starts in the string) . On your label add the GAR field that will print the data if it exists but set Suppression on the Transforms tab to not print the object if the Named Data Source VB field is greater than 1.

So something like

Value = InStr(<your GAR field link>,<your Author field link>,1)

Instead of the Suppression you could use an If Then Else routine to basically Print the field if the value is 0 or print "" if it greater than 1

 

Please sign in to leave a comment.