Show/hide Different Picture On Basis Database Field Value Follow

0
Avatar
Legacy Poster

Hi,

 

I have a database field with the sex of a person. I'd like to check for each label if the person is male or female. If he's male the "Man sysmbol" should be printed and if the person is female the "women symbol" should appear.

 

I tried the following VB script, but get an error "Objects: Type mismatch"

 

Set Pic1 =Objects("Image 1")

Set Pic2 =Objects("Image 2")
 

If (Field("GESCHLECHT") = m) Then

    Pic1.PrintVisibility = True

ElseIf (Field("GESCHLECHT") = w) Then

   Pic2.PrintVisibility = True

Else

  Pic2.PrintVisibility=False

  Pic1.PrintVisibility=False

End If

 

 

5 comments

0
Avatar
Ian Cummings
Moderator
Comment actions Permalink

Create a data sourced picture object on the label design and use an event based VB script as the data source.  For the OnNewRecord event enter in something like the following:

 

If Field("TableName.FieldName") = "Male" Then

   value = "Man.png"

Else

   value = "Woman.png"

End If

0
Avatar
Legacy Poster
Comment actions Permalink

I created the datasourced picture object and have inserted the following for the OnNewRecord event:

 

If Field("GESCHLECHT") = "m" Then

value = "Mars.png"

Else

value = "Venus.png"

End If

 

"GESCHLECHT" is my databasefield, which can have the values "m" or "w"

 

When I'm using the print preview, it doesn't give an error, but no picture is printed.

0
Avatar
Ian Cummings
Moderator
Comment actions Permalink

Have you data sourced the picture object?  Have you specified the correct path to where the image files reside in the picture properties?  If you still have problems I suggest you attach a BarTender document so that we can take a look.

0
Avatar
Legacy Poster
Comment actions Permalink

I think that I have everything right, but I attached the file, so you may take a look.

0
Avatar
Ian Cummings
Moderator
Comment actions Permalink

Perhaps you need to make a reference to the field at the beginning of the script and in the OnAutoSelectedEvent script.  The purpose of this reference is as follows:  Forces reference to a field name in a database.  Useful at the beginning of a script when one of the script's execution paths might skip reference to a field name.  Helps the BarTender to more accurately analyze your script when trying to determine how often it should be run.  For more information, see the BarTender help topic "Forcing Reference to Fields and Share Names."

 

 

ReferenceField("GESCHLECHT")
 

Please sign in to leave a comment.