Views:

Product: LABELVIEW, CODESOFT

Version: 2014 and Later, LABELVIEW Gold and CODESOFT Enterprise

 

1. Add an image to your label that is populated by a variable data source.
NOTE: For more information on how to do this, see this article.

2. Right-click on the image and choose Properties.

3. Select the Visual Basic Scripting tab.

4. Check Activate event call. Select from the dropdown menu Sub OnBeforePrint(ByVal DocObject...).

5. Copy and paste the following script into the text box.

dim invalid, textCancel
'check if image path is invalid
invalid = not ( IsValidImageFile(DocObject) )

'if image path is invalid ask user to confirm job cancel
if invalid = vbtrue then
Dim intUserResponse
intUserResponse = Msgbox("Invalid image path, Cancel job?",308,"Warning")
Select Case intUserResponse
Case 6
Msgbox("Canceled")
Cancel = vbtrue
textCancel = "canceled"
Case 7
Cancel = vbfalse
textCancel = "continued, however"
End Select
end if

'log error for invalid image, note if user canceled or not
if invalid = vbtrue then
dim strFile
dim objFSO
dim objFile
dim strText

strFile = "C:\temp\ScriptLog.txt"
set objFSO = CreateObject("Scripting.FileSystemObject")
'open log file to append, create file if it does not exist
set objFile = objFSO.OpenTextFile(strFile, 8, true)

strText = Document.FullName & " printjob " & textCancel & ", the image " & DocObject.Name & " has an invalid path with data " & DocObject.VariableObject.Value
objFile.WriteLine strText

set objFile = nothing
set objFSO = nothing
end if

6. Click the Green Play button to test the script.

The following window should pop up:

Now, when the print is sent through and the image path is invalid, the following message will appear: